X hits on this document

870 views

0 shares

0 downloads

0 comments

326 / 396

Chapter ‎18   Unsafe code

namespace System { [AttributeUsage( AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event, Inherited = false) ] public class ObsoleteAttribute: Attribute { public ObsoleteAttribute() {...}

public ObsoleteAttribute(string message) {...}

public ObsoleteAttribute(string message, bool error) {...}

public string Message { get {...} }

public bool IsError { get {...} } } }

If a program uses a type or member that is decorated with the Obsolete attribute, the compiler issues a warning or an error. Specifically, the compiler issues a warning if no error parameter is provided, or if the error parameter is provided and has the value false. The compiler issues an error if the error parameter is specified and has the value true.

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.”

17.5 Attributes for Interoperation

Note: This section is applicable only to the Microsoft .NET implementation of C#.

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.313

Document info
Document views870
Page views870
Page last viewedMon Dec 05 18:34:44 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments