X hits on this document

1120 views

0 shares

0 downloads

0 comments

323 / 396

C# LANGUAGE SPECIFICATION

public enum AttributeTargets { Assembly = 0x0001, Module = 0x0002, Class = 0x0004, Struct = 0x0008, Enum = 0x0010, Constructor = 0x0020, Method = 0x0040, Property = 0x0080, Field = 0x0100, Event = 0x0200, Interface = 0x0400, Parameter = 0x0800, Delegate = 0x1000, ReturnValue = 0x2000,

All = Assembly | Module | Class | Struct | Enum | Constructor | Method | Property | Field | Event | Interface | Parameter | Delegate | ReturnValue } }

17.4.2 The Conditional attribute

The attribute Conditional enables the definition of conditional methods. The Conditional attribute indicates a condition by testing a conditional compilation symbol. Calls to a conditional method are either included or omitted depending on whether this symbol is defined at the point of the call. If the symbol is defined, the call is included; otherwise, the call (including evaluation of the parameters of the call) is omitted.

namespace System.Diagnostics { [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class ConditionalAttribute: Attribute { public ConditionalAttribute(string conditionString) {...}

public string ConditionString { get {...} } } }

A conditional method is subject to the following restrictions:

The conditional method must be a method in a class-declaration or struct-declaration. A compile-time error occurs if the Conditional attribute is specified on a method in an interface declaration.

The conditional method must have a return type of void.

The conditional method must not be marked with the override modifier. A conditional method may be marked with the virtual modifier, however. Overrides of such a method are implicitly conditional, and must not be explicitly marked with a Conditional attribute.

The conditional method must not be an implementation of an interface method. Otherwise, a compile-time error occurs.

In addition, a compile-time error occurs if a conditional method is used in a delegate-creation-expression. The example

#define DEBUG

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

Document info
Document views1120
Page views1120
Page last viewedTue Jan 17 05:06:36 UTC 2017
Pages396
Paragraphs9401
Words133190

Comments