Share via


ConditionalAttribute Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.

Inheritance Hierarchy

System. . :: . .Object
  System. . :: . .Attribute
    System.Diagnostics..::..ConditionalAttribute

Namespace:  System.Diagnostics
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<SerializableAttribute> _
<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple := True)> _
Public NotInheritable Class ConditionalAttribute _
    Inherits Attribute
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true)]
public sealed class ConditionalAttribute : Attribute
[SerializableAttribute]
[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple = true)]
public ref class ConditionalAttribute sealed : public Attribute
[<Sealed>]
[<SerializableAttribute>]
[<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true)>]
type ConditionalAttribute =  
    class
        inherit Attribute
    end
public final class ConditionalAttribute extends Attribute

The ConditionalAttribute type exposes the following members.

Constructors

  Name Description
Public method ConditionalAttribute Initializes a new instance of the ConditionalAttribute class.

Top

Properties

  Name Description
Public property ConditionString Gets the conditional compilation symbol that is associated with the ConditionalAttribute attribute.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

You can apply the ConditionalAttribute attribute to methods and classes. However, its use on classes is valid only for types that are derived from Attribute. ConditionalAttribute either will be ignored or will produce a compiler warning or error message if you apply it to any other type.

Applying ConditionalAttribute to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with ConditionalAttribute is defined. Applying ConditionalAttribute to an attribute indicates that the attribute should not be emitted to metadata unless the conditional compilation symbol is defined. Any arguments passed to the method or attribute are still type-checked by the compiler.

ConditionalAttribute is applied to the methods that are defined in the Debug and Trace classes.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Diagnostics Namespace