我个人还没有使用FxCop.我们希望在进行代码分析之前先完成单元测试.但是,你会永久停用哪些规则?您会暂时停用哪些规则以及在哪种情况下停用?
我想在FXCop中创建额外的规则.自定义规则,以帮助确保特定的最佳实践,如检查内联sql.
我真的在寻找好的资源和例子.谢谢!
必须有简单的方法,我不想在每个项目上单独运行代码分析.
我有这样的代码:
public abstract class Base
{
// is going to be used in deriving classes
// let's assume foo is threadsafe
protected static readonly Foo StaticFoo = new Foo();
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio 2008的代码分析弹出以下消息:
CA2104 : Microsoft.Security : Remove the read-only designation from 'Base.StaticFoo' or change the field to one that is an immutable reference type. If the reference type 'Foo' is, in fact, immutable, exclude this message.
我的设计是否存在本质上的缺陷,或者我可以[SuppressMessage]在源代码中添加一个?
今天我的任务是从pydev的django项目中删除小红色X. 大多数情况下,这涉及使用pydev修复导入问题.
我正在使用South进行数据库迁移.南(如果你不知道)生成python模块,pydev不喜欢它们.我不想编辑南方代码,因为它是生成的.
有没有办法指示pydev从分析中排除某些包?有什么比#@UndefinedVariable,整个模块除外?理想情况下,我想忽略名为"迁移"的包.
我想知道是否有任何替代代码分析.我想可以从头开始创建一个代码分析器,虽然这是一项繁琐的工作,但我不确定它是否值得.还有其他非特定于网络的分析仪吗?
谢谢,孙
我responseStream在以下功能中收到警告:
private static string GetResponseString(WebResponse response)
{
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
using (var responseReader = new StreamReader(responseStream))
{
var strResponse = responseReader.ReadToEnd();
return strResponse;
}
}
}
return string.Empty;
}
Run Code Online (Sandbox Code Playgroud)
我从像这样的地方调用这个函数:
var request = (HttpWebRequest)WebRequest.Create(Uri);
request.Headers.Add("Authorization", "GoogleLogin auth=" + this.SecurityToken);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = 5000;
// build the post string
var postString = new StringBuilder();
postString.AppendFormat("registration_id={0}", recipientId);
postString.AppendFormat("&data.payload={0}", message);
postString.AppendFormat("&collapse_key={0}", collapseKey);
// write the post-string as a …Run Code Online (Sandbox Code Playgroud) 在遵守代码分析错误的过程中,我正在将我的属性更改为拥有私有的setter.然后我开始尝试理解为什么多一点.从一些研究,MS说这个:
可写集合属性允许用户使用完全不同的集合替换集合.
答案在这里指出:
在
List<T>对象上添加公共setter 是危险的.
但它没有列出危险的原因.这就是我很好奇的部分.
如果我们有这个集合:
public List<Foo> Foos { get; set; }
Run Code Online (Sandbox Code Playgroud)
为什么要将setter设为私有?显然我们不希望客户端代码替换集合,但如果客户端可以删除每个元素,然后添加他们想要的东西,那有什么意义呢?这与完全替换集合不一样吗?遵循此代码分析规则如何提供价值?
在为我的代码优先EF 5上下文启用迁移后,由于迁移历史记录字符串被添加到项目的resx文件,我开始收到TON的CA1701和CA1703代码分析违规.
我不关心禁用CA1701和CA1703,也不想为每个要添加的迁移抑制100条消息.有没有办法将resx的xml文件或单个resx条目标记为// <自动生成/>以便停止发生?如果我必须禁用这两个规则,那么它只是希望这不是唯一合理的答案!
TIA杰森
我想将更改应用于解决方案的多个文档,但只反映第一个更改,其余部分被拒绝.此链接显示了只有一次可以将更改应用于解决方案.这将是一个什么样的解决方案.我希望链接指向解决方案或代码片段.
这是我的功能:
public static async Task<bool> AddMethod(string solutionPath)
{
var workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync(solutionPath);
ClassDeclarationSyntax cls = SyntaxFactory.ClassDeclaration("someclass");
foreach (var project in solution.Projects)
{
foreach(var document in project.Documents)
{
Document doc = project.GetDocument(document.Id);
var root = await doc.GetSyntaxRootAsync();
var classes = root.DescendantNodes().Where(n => n.IsKind(SyntaxKind.ClassDeclaration));
if (classes.Count() != 0)
{
SyntaxNode FirstClass = classes.First() as ClassDeclarationSyntax;
if (FirstClass != null)
{
var newRoot = root.ReplaceNode(FirstClass, cls);
doc = doc.WithText(newRoot.GetText());
Project proj = doc.Project;
var abc …Run Code Online (Sandbox Code Playgroud)