我正在尝试在vb.net中为nunit(3)编写自定义禁令。最简单的例子(跟随文档)将是:
Namespace MYConstraints
Public Class MyConstraint
Inherits NUnit.Framework.Constraints.Constraint
Public Overrides Function ApplyTo(Of TActual)(actual As TActual) As NUnit.Framework.Constraints.ConstraintResult
Throw New NotImplementedException()
End Function
End Class
End Namespace
(当我继承了nunit ApplyTo
类时,Visual Studio会自动添加Constraint
定义
问题是,它不会编译!
我收到两个错误:
BC30518重载解析失败,因为没有可访问的“那个” 使用这些参数调用:
'公共共享重载Sub(Of TActual)(del As ActualValueDelegate(Of TActual),expr As IResolveConstraint)': 无法推断出类型参数'TActual'。
'公共共享重载Sub(Of TActual)(实际为TActual,表达为IResolveConstraint)': 类型参数'TActual'不能 推断。
和
BC30935成员'公共MustOverride重载函数ApplyTo(Of TActual)(实际为TActual)As ConstraintResult'与此匹配 签名不能被覆盖,因为类'Constraint'包含 具有相同名称和签名的多个成员:
'Public MustOverride重载函数ApplyTo(Of TActual)(实际为 TActual)作为ConstraintResult' 'Public Overridable Overloads Function ApplyTo(Of TActual)(ByRef actual as TActual)As ConstraintResult'
查看Constain class
的{{3}}我看到他们已经定义了两个具有相同签名的变体:
/// <summary>
/// Applies the constraint to an actual value, returning a ConstraintResult.
/// </summary>
/// <param name="actual">The value to be tested</param>
/// <returns>A ConstraintResult</returns>
public abstract ConstraintResult ApplyTo<TActual>(TActual actual);
/// <summary>
/// Applies the constraint to an ActualValueDelegate that returns
/// the value to be tested. The default implementation simply evaluates
/// the delegate but derived classes may override it to provide for
/// delayed processing.
/// </summary>
/// <param name="del">An ActualValueDelegate</param>
/// <returns>A ConstraintResult</returns>
public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
{
#if ASYNC
if (AsyncInvocationRegion.IsAsyncOperation(del))
using (var region = AsyncInvocationRegion.Create(del))
return ApplyTo(region.WaitForPendingOperationsToComplete(del()));
#endif
return ApplyTo(GetTestObject(del));
}
一个是带有pass-by-value参数的抽象,另一个是带引用参数的虚拟,但是在调用时这肯定不足以区分它们吗?
Visual Studio中的工具提示错误(VS 2015 Professional,如果它有所不同)是:
nunit source
所以看起来它正在将ActualValueDelegate<TActual>
解释为vb.net中的ByRef TActual
所以,有两个问题: