A simple question, a weekend question if you like I haven’t used this attribute and I haven’t seen it ‘in action’, but looking at some code today I noticed it for the first time. Although the name is rather self explanatory, I wanted to look up this attribute and find out what it does and what it is used for.
This attribute is used to mark members and or types as obsolete, often because they are deprecated. You are telling that something is not recommended to be used. When the the type or member is used it will give a compiler warning or an error. The attribute can be written just like this:
, but is is recommended that you give an explanation, like so:
[Obsolete(“Nonononono!! don’t use me!!”)]
Both will give just a warning. To throw an error instead you add another argument, a boolean set to true like so:
[Obsolete(“I give u error for using me muahahah”,true)]
Here is an example: