Mono Class Library: System Namespace

System.ObsoleteAttribute Class

Indicates that the target of the current attribute will be removed in future versions of the assembly in which the target is contained. [Edit]

See Also: ObsoleteAttribute Members

System.Object
     System.Attribute
          System.ObsoleteAttribute

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Delegate | System.AttributeTargets.All, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ObsoleteAttribute : Attribute

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

Note:

Marking an item as obsolete provides consumers of that item the information that the item will be not be available in future versions of the assembly in which it is contained. A ObsoleteAttribute has a ObsoleteAttribute.Message property that can be used to suggest alternative ways of obtaining the functionality provided by the item, i.e. a workaround. This class also has a ObsoleteAttribute.IsError property that designates whether a compiler will treat usage of the obsolete item as an error. If this property is false, the compiler will issue a warning if the obsolete item is used and the compiler supports the generation of such warnings.

This attribute can be applied to any valid attribute target except assemblies, parameters, and return values. For a complete list of valid attribute targets, see AttributeTargets .

[Edit]

Example

The following example demonstrates the usage of ObsoleteAttribute to generate a compile-time warning.

C# Example
   
using System;

public class ObsoleteAttributeExample {

  [ObsoleteAttribute("OldMethod is being removed: use NewMethod in future versions.")]
  public static void OldMethod() {

    //Execute some code here
  }

  public static void Main() { 

    OldMethod();
  }
}

An example compile-time result is

ObsoleteAttributeExample.cs(8,4): warning CS0618: 'ObsoleteAttributeExample.OldMethod()' is obsolete: 'OldMethod is being removed: use NewMethod in future versions.'

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0