Search code examples
c#.netsecuritylanguage-design

Require a class to be instanced in C#?


We need to "protect" a class from having static methods for security purposes. We don't want newbie devs following suggestions of coding tools to make a member static as we need to use a constructor with a password to control access to this class.

Is there any way to protect a .NET class in C# to prevent it from have any static members?

Would such a feature, if not available, be worthwhile for a future version of .NET?

Thank you.


Solution

  • You could probably use StyleCop to enforce a custom rule. It would have to be implemented as a build action, though.

    Alternatively, you can use FxCop to analyze the binaries.