Jon Jagger
jon@jaggersoft.com
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 24 Attributesprevious at this levelnext at this level 24.4 Reserved attributesprevious at this levelnext at this level 24.4.3 The Obsolete attribute Paragraph 11 The attribute Obsolete is used to mark types and members of types that should no longer be used.
using System;  
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |  
AttributeTargets.Enum | AttributeTargets.Interface |  
AttributeTargets.Delegate | AttributeTargets.Method |  
AttributeTargets.Constructor | AttributeTargets.Property |  
AttributeTargets.Field | AttributeTargets.Event)]  
public class ObsoleteAttribute: Attribute  
{  
   public ObsoleteAttribute() {...}  
   public ObsoleteAttribute(string message) {...}  
   public ObsoleteAttribute(string message, bool error) {...}  
   public string Message { get {...} }  
   public bool IsError{ get {...} }  
}  
Paragraph 21 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. 2 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. 3 The compiler shall issue a compile-time error if the error parameter is specified and has the value true. [Example: In the example
[Obsolete("This class is obsolete; use class B instead")]  
class A  
{  
   public void F() {}  
}  
class B  
{  
   public void F() {}  
}  
class Test  
{  
   static void Main() {  
      A a = new A(); // warning  
      a.F();  
   }  
}  
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]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS