通过通用助手编写合约
在下面的示例中是否需要使用 [ContractAbbreviator]
属性。如果是,那么即使没有它它也能工作。任何人都可以验证此代码的正确性吗?
/** helper usage class **/
public class UserDataFethcer
{
public UserData GetUserData(string Userid)
{
ContractsHelper.ValidateString(userid);
}
}
/** contracts usage class **/
public static class 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);
}
}
我发现当我使用 [ContractAbbreviator]
时,在 ContractsHelper
中执行 ValidateString
期间,当我删除[ContractAbbreviator]
属性,它工作正常。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您在项目的代码合同选项中设置的内容。您是否打开了运行时合同检查?
It depends on what you have set in the Code Contracts options for the project. Have you got run-time contract checking turned on?