2 <clause number="24.4.3" title="The Obsolete attribute">
3 <paragraph>The attribute Obsolete is used to mark types and members of types that should no longer be used. <code_example><![CDATA[
5 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
6 AttributeTargets.Enum | AttributeTargets.Interface |
7 AttributeTargets.Delegate | AttributeTargets.Method |
8 AttributeTargets.Constructor | AttributeTargets.Property |
9 AttributeTargets.Field | AttributeTargets.Event)]
10 public class ObsoleteAttribute: Attribute
12 public ObsoleteAttribute() {...}
13 public ObsoleteAttribute(string message) {...}
14 public ObsoleteAttribute(string message, bool error) {...}
15 public string Message { get {...} }
16 public bool IsError{ get {...} }
18 ]]></code_example></paragraph>
19 <paragraph>If a program uses a type or member that is decorated with the Obsolete attribute, then the compiler shall issue a warning or error in order to alert the developer, so the offending code can be fixed. Specifically, the compiler shall issue a warning if no error parameter is provided, or if the error parameter is provided and has the value false. The compiler shall issue a compile-time error if the error parameter is specified and has the value true. </paragraph>
21 <example>[Example: In the example <code_example><![CDATA[
22 [Obsolete("This class is obsolete; use class B instead")]
34 A a = new A(); // warning
38 ]]></code_example>the class A is decorated with the Obsolete attribute. Each use of A in Main results in a warning that includes the specified message, "This class is obsolete; use class B instead." end example]</example>