fxcop

How does one implement FxCop / static analysis on an existing code base

家住魔仙堡 提交于 2019-11-30 15:26:03
What are some of the strategies that are used when implementing FxCop / static analysis on existing code bases with existing violations? How can one most effectively reduce the static analysis violations? Make liberal use of [SuppressMessage] attribute to begin with. At least at the beginning. Once you get the count to 0 via the attribute, you then put in a rule that new checkins may not introduce FxCop violations. Visual Studio 2008 has a nice code analysis feature that allows you to ensure that code analysis runs on every build and you can treat warnings as errors. That might slow things

Parameter naming: filename or fileName?

故事扮演 提交于 2019-11-30 13:06:16
问题 I try to be grammatically correct in my naming*. I've always used filename instead of fileName . The java convention also seems to use this, but FxCop prefers fileName . There's a discussion on WikiPedia about it. The more I read, the more I feel I'm right (which is quite usual! :) ). Does anyone have a definitive answer or is this merely something subjective? * I just hope there are no grammar errors in this post! 回答1: It is acceptable English to write "filename" or "file name". When you

CA1500 vs. SA1309 - Which one wins?

本小妞迷上赌 提交于 2019-11-30 11:08:24
I'll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I'd like to see what the general consensus is with regard to these two rules. Rule CA1500 says don't make parameter names and private field names the same. Rule SA1309 , on the other hand, says don't prefix members with underscore or "m_". This leaves us with little options for distinguishing private backing fields from their corresponding parameters. Take these examples. SA1309 complains: class SomeClass { int _someField;

Excluding Code Analysis rule in source

房东的猫 提交于 2019-11-30 08:11:31
In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels. I'd like to suppress those methods in source, so I copied the suppression code generated by FxCop into AssemblyInfo.cs, but it doesn't work. This is the attribute that FxCop copied to the clipboard. [module: SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", Scope = "member", Target = "WindowsClient.MainForm

Nested using statements and Microsoft code Analyses

北城余情 提交于 2019-11-30 06:27:27
Recently I switched on additional code analyses rules. To my surprise I saw a violation in a place I was always considering as the best practice. If I have two nested disposables I am putting two using statements like this: using (StringReader strReader = new StringReader(xmlString)) using (XmlReader xmlReader = XmlReader.Create(strReader)) { result.ReadXml(xmlReader); } This also corresponds to the high rated Q&A Nested using statements in C# The violation I get states following: Warning 18 CA2202 : Microsoft.Usage : Object 'strReader' can be disposed more than once in method '????'. To avoid

What's the proper naming convention for a property 'ID' : ID or Id?

回眸只為那壹抹淺笑 提交于 2019-11-30 06:03:41
Pretty simple question: When i have a persistable object, it usually has a property called ID (for abstract classes). So .. is the naming convention ID or Id? eg. public int ID { get; set; } or public int Id { get; set; } cheers :) PS. This is for .NET btw. FXCop conformat would be a bonus. I usually go with Identifier . If I really want to keep it short (as part of a longer identifier, for example), I use Id, unless it's a parameter or private member. The .NET Framework Naming Guidelines say this: An acronym is a word that is formed from the letters of words in a term or phrase. For example,

FxCop for .NET 4.0

泪湿孤枕 提交于 2019-11-30 05:38:16
I know Visual Studio 2010 has a new Code Analysis tool built in , but that is only for the premium and ultimate editions. From what I can see the latest FxCop supports .NET 3.5 SP1 . Searching I wasn't able to find any references to an FxCop for .NET 4.0. Is there plans to continue to offer FxCop and for it to support .NET 4.0? Where would I find more information about it and download it? The latest version of FXCop (v10) is bundled with the install of the latest Windows SDK for Windows 7 and .Net 4, released on 5/19/2010. From Microsoft - Full ISOs Once the SDK is installed you can find the

what does this security warning mean (.Net Process class)?

点点圈 提交于 2019-11-30 04:59:44
问题 I am using VSTS 2008 + .Net 2.0 + C#. And I am running Code Analysis after build. I got the following confusing security warning. Here is the warning and related code, any ideas what is wrong? If there is security warning, how to fix it? System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); myProcess.StartInfo.FileName = "IExplore.exe"; myProcess.StartInfo.Arguments = @"default.html"; myProcess.StartInfo.Verb = "runas"; myProcess.Start(); warning : CA2122 : Microsoft

How to get the method actually called by the callvirt IL instruction within FxCop

孤人 提交于 2019-11-30 04:37:42
问题 I'm still trying to get my FxCop rule working. As part of this, i need to work out what methods a method calls. Previously i was using CallGraph.CallersFor() (doing it in reverse, which is my final aim anyway), however it appears to have the same issue i describe below. As an alternative to using the CallGraph class i tried visiting all method calls to build a dictionary, based on this code: public override void VisitMethodCall(MethodCall call) { Method CalledMethod = (call.Callee as

Treat Warnings as Errors has no effect

纵然是瞬间 提交于 2019-11-30 04:05:12
问题 In my project's settings in Visual Studio, I have set 'Treat warnings as errors' to 'All'. The Warning level is set to 4. I tested this by deliberately introducing code that violates CA1305, but it builds (and rebuilds) successfully, returning a Warning. What I expected was that the build would fail and an Error would be returned. Is my understanding wrong? 回答1: Code Analysis uses a different mechanism to treat warnings as errors. To have Code Analysis warnings treated as such, add a new Code