나는 CodeContracts에서 다음과 같은 제안을 구현하고 싶습니다 : 그것은 내가이 일어날 수 있도록 대상 속성 SupressMessage을 사용할 수있을 것 같은 느낌프레임 워크 메서드에서 SuppressMessage를 사용할 수 있습니까?
CodeContracts: MyModule: Method MyModule.MyClass.MyMethod:
To mask *all* warnings issued like the precondition add the attribute:
[SuppressMessage("Microsoft.Contracts", "RequiresAtCall-propertyAccessor != null")]
to the method
System.Linq.Expressions.Expression.Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)
. 그러나 이것이 프레임 워크 방법이기 때문에 확실하지 않습니다.
//doesn't work
[module: SuppressMessage("Microsoft.Contracts", "RequiresAtCall-propertyAccessor != null", Scope = "Member", Target = "System.Linq.Expressions.Expression.Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)", Justification = "This isn't covered by Linq Contracts yet.")]
어떻게 전 세계적으로이 경고를 억제 할 수있는, 그래서 나는베이스 라인 또는 callsite 경고의 모두를 억제 할 필요가 없습니다?
EDIT: The specific usage that requires this measure is:
void mymethod()
{
var myObserver = new PropertyObserver<MyViewModel>();
//this line throws the error, within the n => n.Value expression
myObserver.RegisterHandler(n => n.Value, OnValueChanged);
}
public class PropertyObserver<TPropertySource> where TPropertySource : INotifyPropertyChanged
{
public PropertyObserver<TPropertySource> RegisterHandler(
Expression<Func<TPropertySource, object>> expression,
Action<TPropertySource> handler)
{
//what this does is irrelevant; the violation occurs in the method call
}
}
//n => n.Value decompiles to the following
public static MemberExpression Property (Expression expression, MethodInfo propertyAccessor)
{
//and this line is the message I want to suppress, but it's in the .NET framework.
ContractUtils.RequiresNotNull(propertyAccessor, "propertyAccessor");
ValidateMethodInfo(propertyAccessor);
return Property (expression, GetProperty(propertyAccessor));
}
당신이'Contract.Assume'를 사용하지 않는 이유가 거기에 석고로이 ...와 코드가 것입니다? 너무 많은 사건? – porges
우리는 Contract.Assume에서 일반적으로 멀어 지려고 노력했습니다. 그렇습니다. 몇 가지 사례가 있습니다. 우리는 계속 더 많이 추가하고 있습니다. –
그렇다면 문제는 Expression/MethodInfos를 획득하는 다양한 방법이 결과가 null이 아니란 것을 '보장'하지 않는다는 것입니다. http://social.msdn.microsoft.com/Forums/en-NZ/codecontracts/thread/d8e2c2ad-de37-42ef-a854-02052d821975와 같은 래퍼 메서드를 사용 해본 적이 있습니까? 그렇게하면 한 장소에서'Assume '만하면되므로'Assume' 사용이 최소화됩니다. – porges