Export (0) Print
Expand All

ConditionalAttribute Constructor

Initializes a new instance of the ConditionalAttribute class, specifying the name of the attribute that enables the calling of the conditional method.

[Visual Basic]
Public Sub New( _
   ByVal conditionString As String _
)
[C#]
public ConditionalAttribute(
   string conditionString
);
[C++]
public: ConditionalAttribute(
   String* conditionString
);
[JScript]
public function ConditionalAttribute(
   conditionString : String
);

Parameters

conditionString
A string that contains the preprocessing identifier that makes the target method of the current instance callable.

Example

[Visual Basic, C#, C++] The following console application example demonstrates the use of ConditionalAttribute with a particular compiler that supports the use of this attribute.

[Visual Basic] 
<Conditional("CONDITION1"), Conditional("CONDITION2")> _
Public Sub Sub1()
    Sub2()
    Sub3()
End Sub

<Conditional("CONDITION1")> _
Public Sub Sub2()
    Debug.WriteLine("CONDITION1 and DEBUG are defined")
End Sub

<Conditional("CONDITION2")> _
Public Sub Sub3()
    Debug.WriteLine("CONDITION2 and DEBUG are defined")
    Trace.WriteLine("CONDITION2 and TRACE are defined")
End Sub

[C#] 
[Conditional("CONDITION1")]
public static void Method1()
{
    Debug.Write("Method1 - DEBUG and CONDITION1 are specified\n");
    Trace.Write("Method1 - TRACE and CONDITION1 are specified\n");
}

[Conditional("CONDITION1"), Conditional("CONDITION2")]    
public static void Method2()
{
    Debug.Write("Method2 - DEBUG, CONDITION1 or CONDITION2 are specified\n");
}

[C++] 
/*
C++ with Managed Extensions uses the C++ standard preprocessor.  Use the 
preprocessor directives rather than this attribute.
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

ConditionalAttribute Class | ConditionalAttribute Members | System.Diagnostics Namespace

Show:
© 2015 Microsoft