代码分析是否不考虑代码合同? [英] Does code analysis not take Code Contracts into account?

查看:62
本文介绍了代码分析是否不考虑代码合同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

		public PackageManager(PackageManifestType manifestType, Guid packageId, string customerId, string applicationId, DirectoryInfo packageDirectory)
{
Contract.Requires(Enum.IsDefined(typeof(PackageManifestType), manifestType));
Contract.Requires(packageId != Guid.Empty);
Contract.Requires(!string.IsNullOrEmpty(customerId));
Contract.Requires(!string.IsNullOrEmpty(applicationId));
Contract.Requires(packageDirectory != null);
Contract.Requires(packageDirectory.Exists);
Contract.Ensures(_manifest != null);
Contract.Ensures(_packageDirectory != null);

_packageDirectory = packageDirectory;
PackageId = packageId;
CustomerId = customerId;
ApplicationId = applicationId;
ManifestType = manifestType;
_manifest = GenerateManifest(manifestType, packageId, customerId, applicationId, packageDirectory);
}


并获得警告:警告  4  CA. 1062:Microsoft.Design:在外部可见方法'PackageManager.PackageManager(PackageManifestType,Guid,string,string,DirectoryInfo)'中,在使用之前验证参数'packageDirectory'。 

and get the waring: Warning 4 CA1062 : Microsoft.Design : In externally visible method 'PackageManager.PackageManager(PackageManifestType, Guid, string, string, DirectoryInfo)', validate parameter 'packageDirectory' before using it. 

推荐答案

奇怪的是,它并没有为每个参数提供这些警告。 只是其中一些。
The weird thing is that it doesn't give me these warning for every parameter.  Just some of them.


这篇关于代码分析是否不考虑代码合同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆