开发者

code contracts via generic helper

开发者 https://www.devze.com 2023-03-17 02:06 出处:网络
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.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消