stylecop

“ using”指令应该在名称空间之内还是之外?

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-06 09:48:35
问题: I have been running StyleCop over some C# code, and it keeps reporting that my using directives should be inside the namespace. 我一直在通过某些C#代码运行 StyleCop ,并且一直在报告我的 using 指令应该在名称空间内。 Is there a technical reason for putting the using directives inside instead of outside the namespace? 是否有技术上的理由将 using 指令放在名称空间的内部而不是外部? 解决方案: 参考一: https://stackoom.com/question/WbH/using-指令应该在名称空间之内还是之外 参考二: https://oldbug.net/q/WbH/Should-using-directives-be-inside-or-outside-the-namespace 来源: oschina 链接: https://my.oschina.net/u/4438370/blog/4299035

SonarScanner (C#) not honoring in-code StyleCop warning suppression

守給你的承諾、 提交于 2020-06-28 03:50:23
问题 I am trying to use SonarQube for static code analysis for my organization. All our C# projects already have StyleCop enabled which has helped us a lot in terms of code readability. Now we want to utilize SonarQube for static code analysis. I successfully hosted the SonarQube server locally following the guidelines provided here. I am able to run the analysis successfully and generate the sonarqube report when there are no warning-suppressions in the code. ISSUE: Sonarqube does not consider in

我应该使用int还是Int32

梦想与她 提交于 2020-03-08 09:44:10
在C#中, int 和 Int32 是同一件事,但是我读过很多次,没有给出原因, int 比 Int32 更可取。 有原因吗,我应该在乎吗? #1楼 在定义变量时,我总是使用别名类型(int,字符串等),在访问静态方法时,我总是使用真实名称: int x, y; ... String.Format ("{0}x{1}", x, y); 看到类似int.TryParse()的东西看起来很丑。 除了样式,我没有其他原因。 #2楼 根据Visual Studio 2012中的即时窗口,Int32为int,Int64为long。 这是输出: sizeof(int) 4 sizeof(Int32) 4 sizeof(Int64) 8 Int32 int base {System.ValueType}: System.ValueType MaxValue: 2147483647 MinValue: -2147483648 Int64 long base {System.ValueType}: System.ValueType MaxValue: 9223372036854775807 MinValue: -9223372036854775808 int int base {System.ValueType}: System.ValueType MaxValue: 2147483647

常量的C#命名约定?

拈花ヽ惹草 提交于 2020-02-25 23:22:21
private const int THE_ANSWER = 42; 要么 private const int theAnswer = 42; 我个人认为,对于现代IDE,我们应该使用camelCase,因为ALL_CAPS看起来很奇怪。 你怎么看? #1楼 Microsoft在其文章 Constants(C#编程指南)中 给出了以下示例: class Calendar3 { const int months = 12; const int weeks = 52; const int days = 365; const double daysPerWeek = (double) days / (double) weeks; const double daysPerMonth = (double) days / (double) months; } 因此,对于常量, 看来 Microsoft建议使用 camelCasing 。 但是请注意,这些常量是 在本地 定义的。 可以说,外部可见常量的命名引起了人们的极大兴趣。 实际上,Microsoft在.NET类库中将其 公共常量 记录为 field 。 这里有些例子: Int32.MaxValue String.Empty (实际上是 static readonly ) 数学PI 数学 前两个是 PascalCasing 示例。

Suppressing the StyleCop Warnings at the global level

荒凉一梦 提交于 2020-02-21 11:21:10
问题 How to suppress the StyleCop warnings globally in the solution? The solution is continually built using Jenkins (continuous build and integration tool), and it applies all the StyleCop rules. The solution uses TAB character instead of 4 spaces as it is the standard taken by my dev team. Because of this, several SA1027 warnings are thrown by StlyeCop. How do I remove SA1027 warning from Jenkins? That would also help. Giving the SuppressMessage on every C# file would not look nice. That's why I

Why can't I use constants in [SuppressMessage(…)] together with StyleCop?

不问归期 提交于 2020-01-15 03:11:14
问题 I would like to place the strings needed for suppression of StyleCop warnings as constants in a class, so that I do not need to place strings all over and benefit from the find all references function to find out how many times I have suppressed which rule. public class Rules { public const string Naming = "Microsoft.StyleCop.CSharp.NamingRules"; public const string SA1310 = "SA1310:FieldNamesMustNotContainUnderscore"; } Decorating my class as follows [SuppressMessage(Rules.Naming, Rules

How to supress StyleCop warning “SA1201: All methods must be placed after all properties.”? [duplicate]

£可爱£侵袭症+ 提交于 2020-01-04 06:54:45
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to suppress a StyleCop warning? I'm writing a group of methods which are a mix of private/public and need to put into the same region (using #region). I used method mentioned in here but I can not get this warning supressed. Please help. [Edit] I need to supress this particular warning only - not for the whole project/solution. But I'm willing to know how to do that ^_^ 回答1: Are you happy to disable the rule

Adding Author Name in document Header using StyleCop

南笙酒味 提交于 2020-01-03 05:44:30
问题 I am using StyleCop with Visual Studio. Whenever i add a new file it adds few information like company name ,copyright details. I want to add author name and creation date also .Is it possible to update the StyleCop Setting somewhere to support this ? 回答1: http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/25/sharing-source-analysis-settings-across-projects.aspx http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/25/managing-source-analysis-project-settings.aspx Between them you are

CA1500 vs. SA1309 - Which one wins?

百般思念 提交于 2019-12-30 03:44:04
问题 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