Wednesday, December 10, 2014

Obsolete Attribute

The Obsolete attribute marks a program entity as one that is no longer recommended for use. Each use of an entity marked obsolete will subsequently generate a warning or an error, depending on how the attribute is configured



[System.Obsolete("use class ANew")]
class AOld
{
  public void Method() { }
}

class ANew
 {
    [System.Obsolete("use NewMethod", true)]
    public void OldMethod() { }
    public void NewMethod() { }
 }

static void Main(string[] args)
 { 
   // Generates 2 warnings:
   AOld aOld = new AOld();///Warn: is obsolete: use class ANew

   // Generate no errors or warnings:
   ANew aNew = new ANew();
   aNew.NewMethod();

   // Generates an error, terminating compilation:
   //aNew.OldMethod();//Error: is obsolete: use NewMethod
}

 

No comments:

Post a Comment