Is the use of [ContractAbbreviator]
attribute in the below sample needed. If yes, then it works even without it. Can any one verify this code for correctness.
/** helper usage class **/
public class UserDataFethcer
{
public UserData GetUserData(string Userid)
{
ContractsHelper.ValidateString(userid);
}
}
/** contracts usage class **/
public static class开发者_如何学C ContractsHelper
{
[ContractAbbreviator] // is this needed or not..
public static void ValidateString(params string[] stringParameters)
{
Contract.Requires<ArgumentException>(Contract.ForAll(stringParameters, strParams => !string.IsNullOrEmpty(strParams)), Message);
}
}
I find that when i use the [ContractAbbreviator]
, during execution of the ValidateString
in ContractsHelper
the lines of code are skipped, when i remove the [ContractAbbreviator]
attribute, it works fine.
It depends on what you have set in the Code Contracts options for the project. Have you got run-time contract checking turned on?
精彩评论