1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<?xml version="1.0" encoding="utf-8"?>
<Type Name="ConditionalAttribute" FullName="System.Diagnostics.ConditionalAttribute" FullNameSP="System_Diagnostics_ConditionalAttribute" Maintainer="ecma">
<TypeSignature Language="ILASM" Value=".class public sealed serializable ConditionalAttribute extends System.Attribute" />
<TypeSignature Language="C#" Value="public sealed class ConditionalAttribute : Attribute" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable sealed beforefieldinit ConditionalAttribute extends System.Attribute" />
<MemberOfLibrary>BCL</MemberOfLibrary>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyPublicKey>[00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ]</AssemblyPublicKey>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ThreadingSafetyStatement>All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.</ThreadingSafetyStatement>
<Base>
<BaseTypeName>System.Attribute</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute>
<AttributeName>System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true)</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Runtime.InteropServices.ComVisible(true)</AttributeName>
</Attribute>
</Attributes>
<Docs>
<example>
<para> The following example demonstrates the use of
<see cref="T:System.Diagnostics.ConditionalAttribute" /> with a
particular compiler that supports the use of this
attribute. The <see cref="P:System.Diagnostics.ConditionalAttribute.ConditionString" /> property of the current
attribute is initialized as "DEBUG".</para>
<c>
<code lang="C#">using System;
using System.Diagnostics;
public class MyClass {
[ConditionalAttribute("DEBUG")]
public static void Display() {
Console.WriteLine("Compiled with DEBUG");
}
}
public class TestCondition {
public static void Main() {
Console.WriteLine("How was this compiled?");
MyClass.Display();
Console.WriteLine("<eop>");
}
}
</code>
</c>
<para> When this code is compiled with the
compilation-variable DEBUG defined at the callsite, the
output when run is </para>
<c>
<para>
How was this compiled?</para>
<para>Compiled with DEBUG</para>
<para><eop>
</para>
</c>
<para> When this code is
compiled without the compilation-variable DEBUG defined at the callsite, the
output when run is</para>
<c>
<para>
How was this compiled?</para>
<para><eop>
</para>
</c>
</example>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>You can apply the <see cref="T:System.Diagnostics.ConditionalAttribute" /> attribute to methods and classes. However, its use on classes is valid only for types that are derived from <see cref="T:System.Attribute" />. <see cref="T:System.Diagnostics.ConditionalAttribute" /> either will be ignored or will produce a compiler warning or error message if you apply it to any other type.</para>
<para>Applying <see cref="T:System.Diagnostics.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 <see cref="T:System.Diagnostics.ConditionalAttribute" /> is defined. You will get a compilation error in Visual Studio if you apply this attribute to a method that does not return void. Applying <see cref="T:System.Diagnostics.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.</para>
<para>You can use the following techniques to define conditional compilation symbols: </para>
<list type="bullet">
<item>
<para>Use compiler command-line options; for example, <system>/define:DEBUG</system>.</para>
</item>
<item>
<para>Use environment variables in the operating system shell; for example, <system>set DEBUG=1</system>.</para>
</item>
<item>
<para>Use pragmas in the source code; for example, define the compilation variable as follows: </para>
<code>#define DEBUG</code>
<code>#Const DEBUG=True</code>
<para>To undefine the variable, use the following: </para>
<code>#Undef DEBUG</code>
<code>#Const DEBUG=False</code>
</item>
</list>
<para>Compilers that comply with the Common Language Specification (CLS) are permitted to ignore <see cref="T:System.Diagnostics.ConditionalAttribute" />. The C#, Visual Basic, and C++ compilers support <see cref="T:System.Diagnostics.ConditionalAttribute" />; the JScript compiler does not support the attribute.</para>
<block subset="none" type="note">
<para>In Visual Basic, the AddressOf operator is not affected by this attribute. For example, Call CType(AddressOf delegate, Action) always invokes delegate, although Call delegate() might not.</para>
</block>
<para>
<see cref="T:System.Diagnostics.ConditionalAttribute" /> is applied to the methods that are defined in the <see cref="T:System.Diagnostics.Debug" /> and <see cref="T:System.Diagnostics.Trace" /> classes. </para>
<para>For more information about how to use attributes, see <format type="text/html"><a href="30386922-1e00-4602-9ebf-526b271a8b87">Extending Metadata Using Attributes</a></format>.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Indicates to compilers that a method call or attribute should be ignored unless a specified conditional compilation symbol is defined.</para>
</summary>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="ILASM" Value="public rtspecialname specialname instance void .ctor(string conditionString)" />
<MemberSignature Language="C#" Value="public ConditionalAttribute (string conditionString);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string conditionString) cil managed" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue />
<Parameters>
<Parameter Name="conditionString" Type="System.String" />
</Parameters>
<Docs>
<remarks>
<para>This constructor initializes the <see cref="P:System.Diagnostics.ConditionalAttribute.ConditionString" /> property of the current instance using
<paramref name="conditionString" />.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Initializes a new instance of the <see cref="T:System.Diagnostics.ConditionalAttribute" /> class.</para>
</summary>
<param name="conditionString">
<attribution license="cc4" from="Microsoft" modified="false" />A string that specifies the case-sensitive conditional compilation symbol that is associated with the attribute. </param>
</Docs>
<Excluded>0</Excluded>
</Member>
<Member MemberName="ConditionString">
<MemberSignature Language="ILASM" Value=".property string ConditionString { public hidebysig specialname instance string get_ConditionString() }" />
<MemberSignature Language="C#" Value="public string ConditionString { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string ConditionString" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<value>
<para>A <see cref="T:System.String" />
that contains the pre-processing identifier that makes callable the target
method of the current instance.</para>
</value>
<remarks>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>This property is read-only.</para>
</remarks>
<summary>
<attribution license="cc4" from="Microsoft" modified="false" />
<para>Gets the conditional compilation symbol that is associated with the <see cref="T:System.Diagnostics.ConditionalAttribute" /> attribute.</para>
</summary>
</Docs>
<Excluded>0</Excluded>
</Member>
</Members>
<TypeExcluded>0</TypeExcluded>
</Type>
|