Obsolete

The Obsolete aspect can be attached to types and members to mark them as obsolete or deprecated. The aspect has no effect on code generation, but any code that will use the obsolete type or member will generate a warning or – optionally – an error.

The aspect takes two optional parameters. The first is a string that can provide a custom message to replace the more generic default message generated for the compiler – for example to direct the developer trying to use the API to a better-suited alternative. The second parameter is a boolean that indicates whether trying to access the member should fail with an error (true) or merely generate a warning (false, the default).

The aspect can be applied to individual members or to a whole type. If applied to a whole type, any access of the type or any of its members will trigger the warning (or error).

[Obsolete('Foo is no longer supported, use Bar instead', true)]
method Foo;
begin
end;
[Obsolete("Foo is no longer supported, use Bar instead", true)]
public void Foo()
{
}
@Obsolete("Foo is no longer supported, use Bar instead", true)
public func Foo() {
}
@Obsolete("Foo is no longer supported, use Bar instead", true)
public void Foo()
{
}

Defined by the .NET Framework (on .NET) and by the the core compiler (other platforms)

See Also