-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Public Static Readonly Fields Trigger SA1401 #1320
Comments
Considering that C# 6 made it extremely easy to expose these as properties, my vote is that we not change the current behavior. The framework contains as many examples of properties being used for this purpose (e.g. public static MyClass Empty { get; } = new MyClass(); I'm leaving this marked needs discussion for now to get some more feedback. By the way, welcome to the project @lumberjack4. 😄 Thanks for taking the time to try out the product and file all these issues! 👍 |
Cool! I'm still trying to remember all the new changes. |
See #1308 |
What about dependency properties? Typically when you use the "propdp" snippet you get this generated: public static readonly DependencyProperty FooProperty =
DependencyProperty.Register("Foo", typeof(string), typeof(Class1), new PropertyMetadata(null)); which triggers SA1401. |
@oatkins Can you check the behavior of StyleCop "classic" with code like the previous comment? |
None of the following raises SA1401 in classic SC:
Interestingly, SC is being cautious here. My last example exposes a mutable object as a static field, which isn't good practice... but I would think that someone who's explicitly made something I currently disable SA1401 for WPF projects; I would support never reporting this case so I can turn it back on. |
I would prefer that SA1401 will not be reported for |
Relabeling this as a bug. |
SA1401 is triggered telling me that the field must be private. Recommend ignoring the rule for public static readonly fields, as this is the .NET paradigm for creating empty objects.
The text was updated successfully, but these errors were encountered: