Notify Developer of a "DO NOT USE" Method

If a class is [Serialisable] (i.e. it can be copied around the place as needed) the param-less constructor is needed to deserialise.

I'm guessing that you want to force your code's access to pass defaults for your properties to a parameterised constructor.

Basically you're saying that it's OK for the XmlSerializer to make a copy and then set properties, but you don't want your own code to.

To some extent I think this is over-designing.

Just add XML comments that detail what properties need initialising (and what to).

Don't use [Obsolete], because it isn't. Reserve that for genuinely deprecated methods.


throw new ISaidDoNotUseException();

You could build your own Attribute derived class, say NonCallableAttribute to qualify methods, and then add to your build/CI code analysis task the check to monitor if any code is using those methods.

In my opinion, you really cannot force developers to not use the method, but you could detect when someone broke the rule as soon as possible and fix it.


Prior to VS2013 you could use:

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]

so that it doesn't show up in IntelliSense. If the consumer still wants to use it they can, but it won't be as discoverable.

Keith's point about over-engineering still stands though.


Since VS2013 this feature has been removed. As noted in https://github.com/dotnet/roslyn/issues/37478 this was "by design" and apparently will not be brought back.