Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
618 lines (563 sloc) 37.2 KB
<Type Name="Switch" FullName="System.Diagnostics.Switch">
<TypeSignature Language="C#" Value="public abstract class Switch" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract beforefieldinit Switch extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Diagnostics.Switch" />
<TypeSignature Language="VB.NET" Value="Public MustInherit Class Switch" />
<TypeSignature Language="C++ CLI" Value="public ref class Switch abstract" />
<TypeSignature Language="F#" Value="type Switch = class" />
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Provides an abstract base class to create new debugging and tracing switches.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A switch provides an efficient mechanism for controlling tracing and debugging output at run time using external settings. The <xref:System.Diagnostics.Switch> class implements default behavior for switches, allowing you to change the switch level at run time.
This class is the base class for the <xref:System.Diagnostics.BooleanSwitch>, <xref:System.Diagnostics.SourceSwitch> and the <xref:System.Diagnostics.TraceSwitch> classes. These switches meet most debugging and tracing needs. For more information about trace switches, see [Trace Switches](~/docs/framework/debug-trace-profile/trace-switches.md).
You must enable tracing or debugging to use a switch. The following syntax is compiler specific. If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.
- To enable debugging in C#, add the `/d:DEBUG` flag to the compiler command line when you compile your code, or you can add `#define DEBUG` to the top of your file. In Visual Basic, add the `/d:DEBUG=True` flag to the compiler command line.
- To enable tracing using in C#, add the `/d:TRACE` flag to the compiler command line when you compile your code, or add `#define TRACE` to the top of your file. In Visual Basic, add the `/d:TRACE=True` flag to the compiler command line.
To set the level of your switch, edit the configuration file that corresponds to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all the switches previously set by the application. The configuration file should be formatted like the following example:
```xml
<configuration>
<system.diagnostics>
<switches>
<add name="mySwitch" value="true" />
</switches>
</system.diagnostics>
</configuration>
```
This example configuration section defines a <xref:System.Diagnostics.BooleanSwitch> with the <xref:System.Diagnostics.Switch.DisplayName%2A> property set to `mySwitch` and the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> value set to `true`. Within your application, you can use the configured switch value by creating a <xref:System.Diagnostics.BooleanSwitch> with the same name, as shown in the following code example.
[!code-cpp[Classic Switch Example#4](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic Switch Example/CPP/remarks.cpp#4)]
[!code-csharp[Classic Switch Example#4](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic Switch Example/CS/remarks.cs#4)]
## Examples
The following example shows how to define a new <xref:System.Diagnostics.Switch> class with four levels of tracing that can be used to trace a call stack. You can use the switch to instrument your application to log each time the method is entered or exited.
The first example creates the enumeration used to set the level of the switch.
[!code-cpp[Classic Switch Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic Switch Example/CPP/source.cpp#1)]
[!code-csharp[Classic Switch Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic Switch Example/CS/source.cs#1)]
[!code-vb[Classic Switch Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Switch Example/VB/source.vb#1)]
The following example creates the new switch. The code implements a `Level` property to set the value of the new switch. `Level` calls the protected property <xref:System.Diagnostics.Switch.SwitchSetting%2A> that assigns the value to the new switch. This example also implements two assessor properties to get the assigned value of the switch.
[!code-cpp[Classic Switch Example#2](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic Switch Example/CPP/source.cpp#2)]
[!code-csharp[Classic Switch Example#2](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic Switch Example/CS/source.cs#2)]
[!code-vb[Classic Switch Example#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Switch Example/VB/source.vb#2)]
The following example creates a new switch in `Main`. It creates a new switch and assigns it a value. Then, depending on the switch settings, it outputs debugging messages for entering and leaving the method.
[!code-cpp[Classic Switch Example#3](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic Switch Example/CPP/source.cpp#3)]
[!code-csharp[Classic Switch Example#3](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic Switch Example/CS/source.cs#3)]
[!code-vb[Classic Switch Example#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Switch Example/VB/source.vb#3)]
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>If you need trace levels, or mechanisms for setting switch levels different from those provided by <see cref="T:System.Diagnostics.BooleanSwitch" />, <see cref="T:System.Diagnostics.SourceSwitch" /> and <see cref="T:System.Diagnostics.TraceSwitch" />, you can inherit from <see cref="T:System.Diagnostics.Switch" />. When inheriting from this class, you must implement the <see cref="P:System.Diagnostics.Switch.SwitchSetting" /> method.</para>
</block>
<altmember cref="T:System.Diagnostics.BooleanSwitch" />
<altmember cref="T:System.Diagnostics.TraceSwitch" />
<altmember cref="T:System.Diagnostics.Debug" />
<altmember cref="T:System.Diagnostics.Trace" />
<related type="Article" href="https://msdn.microsoft.com/library/8ab913aa-f400-4406-9436-f45bc6e54fbe">Trace Switches</related>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.Switch" /> class.</summary>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected Switch (string displayName, string description);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor(string displayName, string description) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.Switch.#ctor(System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Protected Sub New (displayName As String, description As String)" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; Switch(System::String ^ displayName, System::String ^ description);" />
<MemberSignature Language="F#" Value="new System.Diagnostics.Switch : string * string -&gt; System.Diagnostics.Switch" Usage="new System.Diagnostics.Switch (displayName, description)" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="displayName" Type="System.String" />
<Parameter Name="description" Type="System.String" />
</Parameters>
<Docs>
<param name="displayName">The name of the switch.</param>
<param name="description">The description for the switch.</param>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.Switch" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When you create a new <xref:System.Diagnostics.Switch> object, the value of the `displayName` parameter is used to find initial switch settings. The default value is an empty string ("").
Within the XML configuration file, you can add a switch and set its value, remove a switch, or clear all the switches previously set by the application. Dynamic changes to the configuration file are not detected while the application is executing. You must stop and restart an application before changes to the configuration file take effect. The configuration file should be formatted like the following example:
```xml
<configuration>
<system.diagnostics>
<switches>
<add name="mySwitch" value="10" />
<add name="myNewSwitch" value="20" />
<remove name="mySwitch" />
<clear/>
</switches>
</system.diagnostics>
</configuration>
```
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>To set the value of the switch, set the <see cref="P:System.Diagnostics.Switch.SwitchSetting" /> property in the constructor.</para>
</block>
<altmember cref="T:System.Diagnostics.Switch" />
<altmember cref="T:System.Diagnostics.BooleanSwitch" />
<altmember cref="T:System.Diagnostics.SourceSwitch" />
<altmember cref="T:System.Diagnostics.TraceSwitch" />
<altmember cref="T:System.Diagnostics.Debug" />
<altmember cref="T:System.Diagnostics.Trace" />
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="protected Switch (string displayName, string description, string defaultSwitchValue);" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig specialname rtspecialname instance void .ctor(string displayName, string description, string defaultSwitchValue) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.Switch.#ctor(System.String,System.String,System.String)" />
<MemberSignature Language="VB.NET" Value="Protected Sub New (displayName As String, description As String, defaultSwitchValue As String)" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; Switch(System::String ^ displayName, System::String ^ description, System::String ^ defaultSwitchValue);" />
<MemberSignature Language="F#" Value="new System.Diagnostics.Switch : string * string * string -&gt; System.Diagnostics.Switch" Usage="new System.Diagnostics.Switch (displayName, description, defaultSwitchValue)" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters>
<Parameter Name="displayName" Type="System.String" Index="0" FrameworkAlternate="netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<Parameter Name="description" Type="System.String" Index="1" FrameworkAlternate="netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
<Parameter Name="defaultSwitchValue" Type="System.String" Index="2" FrameworkAlternate="netcore-1.0;netcore-1.1;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netstandard-2.0;netstandard-2.1;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0" />
</Parameters>
<Docs>
<param name="displayName">The name of the switch.</param>
<param name="description">The description of the switch.</param>
<param name="defaultSwitchValue">The default value for the switch.</param>
<summary>Initializes a new instance of the <see cref="T:System.Diagnostics.Switch" /> class, specifying the display name, description, and default value for the switch.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The `displayName` parameter is used to set the value of the <xref:System.Diagnostics.Switch.DisplayName%2A> property, and the `description` parameter is use to set the value of the <xref:System.Diagnostics.Switch.Description%2A> property. The `defaultSwitchValue` parameter is the value for the switch if the <xref:System.Diagnostics.Switch.Value%2A> property is not set by code or by the configuration file attribute. See the <xref:System.Diagnostics.Switch.%23ctor%28System.String%2CSystem.String%29> overload for additional information.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Attributes">
<MemberSignature Language="C#" Value="public System.Collections.Specialized.StringDictionary Attributes { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance class System.Collections.Specialized.StringDictionary Attributes" />
<MemberSignature Language="DocId" Value="P:System.Diagnostics.Switch.Attributes" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Attributes As StringDictionary" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::Collections::Specialized::StringDictionary ^ Attributes { System::Collections::Specialized::StringDictionary ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Attributes : System.Collections.Specialized.StringDictionary" Usage="System.Diagnostics.Switch.Attributes" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;xamarinandroid-7.1;xamarinios-10.8;xamarinmac-3.0;netframework-4.8">
<AttributeName>System.Xml.Serialization.XmlIgnore</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Collections.Specialized.StringDictionary</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the custom switch attributes defined in the application configuration file.</summary>
<value>A <see cref="T:System.Collections.Specialized.StringDictionary" /> containing the case-insensitive custom attributes for the trace switch.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Diagnostics.Switch.Attributes%2A> property identifies the custom attributes referenced in the application's configuration file. Unreferenced custom attributes are not enumerated. Classes that inherit from the <xref:System.Diagnostics.Switch> class can add custom attributes by overriding the <xref:System.Diagnostics.Switch.GetSupportedAttributes%2A> method and returning a string array of custom attribute names.
## Examples
The following code sample shows how to display the unrecognized attributes for a custom switch.
[!code-csharp[System.Diagnostics.TraceSource#15](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.TraceSource/CS/program.cs#15)]
[!code-vb[System.Diagnostics.TraceSource#15](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.TraceSource/VB/program.vb#15)]
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Description">
<MemberSignature Language="C#" Value="public string Description { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Description" />
<MemberSignature Language="DocId" Value="P:System.Diagnostics.Switch.Description" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Description As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::String ^ Description { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Description : string" Usage="System.Diagnostics.Switch.Description" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a description of the switch.</summary>
<value>The description of the switch. The default value is an empty string ("").</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This property should indicate the function of the switch; for example, "Enables tracing for a directory watcher component." The value is set by the `descriptor` parameter in the <xref:System.Diagnostics.Switch.%23ctor%2A> constructor.
]]></format>
</remarks>
<altmember cref="T:System.Diagnostics.Switch" />
<altmember cref="T:System.Diagnostics.BooleanSwitch" />
<altmember cref="T:System.Diagnostics.TraceSwitch" />
<altmember cref="T:System.Diagnostics.Debug" />
<altmember cref="T:System.Diagnostics.Trace" />
</Docs>
</Member>
<Member MemberName="DisplayName">
<MemberSignature Language="C#" Value="public string DisplayName { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string DisplayName" />
<MemberSignature Language="DocId" Value="P:System.Diagnostics.Switch.DisplayName" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property DisplayName As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::String ^ DisplayName { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.DisplayName : string" Usage="System.Diagnostics.Switch.DisplayName" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets a name used to identify the switch.</summary>
<value>The name used to identify the switch. The default value is an empty string ("").</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
When you create a new <xref:System.Diagnostics.Switch> object, the <xref:System.Diagnostics.Switch.DisplayName%2A> finds initial switch settings. For more information, see the <xref:System.Diagnostics.Switch.%23ctor%2A> constructor and [How to: Create, Initialize and Configure Trace Switches](~/docs/framework/debug-trace-profile/how-to-create-initialize-and-configure-trace-switches.md) in the Visual Studio documentation.
## Examples
The following code example displays the display name for the switch in use by a trace source. This code example is part of a larger example that can be found in the <xref:System.Diagnostics.TraceSource> class summary.
[!code-csharp[System.Diagnostics.TraceSource#10](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.TraceSource/CS/program.cs#10)]
[!code-vb[System.Diagnostics.TraceSource#10](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.TraceSource/VB/program.vb#10)]
]]></format>
</remarks>
<altmember cref="T:System.Diagnostics.Switch" />
<altmember cref="T:System.Diagnostics.BooleanSwitch" />
<altmember cref="T:System.Diagnostics.TraceSwitch" />
<altmember cref="T:System.Diagnostics.Debug" />
<altmember cref="T:System.Diagnostics.Trace" />
</Docs>
</Member>
<Member MemberName="GetSupportedAttributes">
<MemberSignature Language="C#" Value="protected internal virtual string[] GetSupportedAttributes ();" />
<MemberSignature Language="ILAsm" Value=".method familyorassemblyhidebysig newslot virtual instance string[] GetSupportedAttributes() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.Switch.GetSupportedAttributes" />
<MemberSignature Language="VB.NET" Value="Protected Friend Overridable Function GetSupportedAttributes () As String()" />
<MemberSignature Language="C++ CLI" Value="protected public:&#xA; virtual cli::array &lt;System::String ^&gt; ^ GetSupportedAttributes();" />
<MemberSignature Language="F#" Value="abstract member GetSupportedAttributes : unit -&gt; string[]&#xA;override this.GetSupportedAttributes : unit -&gt; string[]" Usage="switch.GetSupportedAttributes " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String[]</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Gets the custom attributes supported by the switch.</summary>
<returns>A string array that contains the names of the custom attributes supported by the switch, or <see langword="null" /> if there no custom attributes are supported.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default implementation for the <xref:System.Diagnostics.Switch.GetSupportedAttributes%2A> method returns `null`. If a switch is added in a configuration file and custom attributes are specified that are not included in the string array returned by <xref:System.Diagnostics.Switch.GetSupportedAttributes%2A>, a <xref:System.Configuration.ConfigurationException> is thrown when the switch is loaded.
## Examples
The following code sample shows an override of the <xref:System.Diagnostics.Switch.GetSupportedAttributes%2A> method for a custom switch.
[!code-csharp[System.Diagnostics.TraceSource#34](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Diagnostics.TraceSource/CS/program.cs#34)]
[!code-vb[System.Diagnostics.TraceSource#34](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Diagnostics.TraceSource/VB/program.vb#34)]
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>When inheriting from the <see cref="T:System.Diagnostics.Switch" /> class or a derived class, you can override the <see cref="M:System.Diagnostics.Switch.GetSupportedAttributes" /> method to provide custom attributes for your class.</para>
</block>
</Docs>
</Member>
<Member MemberName="OnSwitchSettingChanged">
<MemberSignature Language="C#" Value="protected virtual void OnSwitchSettingChanged ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void OnSwitchSettingChanged() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.Switch.OnSwitchSettingChanged" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub OnSwitchSettingChanged ()" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; virtual void OnSwitchSettingChanged();" />
<MemberSignature Language="F#" Value="abstract member OnSwitchSettingChanged : unit -&gt; unit&#xA;override this.OnSwitchSettingChanged : unit -&gt; unit" Usage="switch.OnSwitchSettingChanged " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Invoked when the <see cref="P:System.Diagnostics.Switch.SwitchSetting" /> property is changed.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
<xref:System.Diagnostics.Switch.OnSwitchSettingChanged%2A> is invoked the first time a switch reads the <xref:System.Diagnostics.Switch.SwitchSetting%2A> value from the configuration file and is invoked again each time the switch's value is changed.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="OnValueChanged">
<MemberSignature Language="C#" Value="protected virtual void OnValueChanged ();" />
<MemberSignature Language="ILAsm" Value=".method familyhidebysig newslot virtual instance void OnValueChanged() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Diagnostics.Switch.OnValueChanged" />
<MemberSignature Language="VB.NET" Value="Protected Overridable Sub OnValueChanged ()" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; virtual void OnValueChanged();" />
<MemberSignature Language="F#" Value="abstract member OnValueChanged : unit -&gt; unit&#xA;override this.OnValueChanged : unit -&gt; unit" Usage="switch.OnValueChanged " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Invoked when the <see cref="P:System.Diagnostics.Switch.Value" /> property is changed.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default implementation parses the new value of the <xref:System.Diagnostics.Switch.Value%2A> property to an integer value which it uses to set the <xref:System.Diagnostics.Switch.SwitchSetting%2A> property.
]]></format>
</remarks>
<block subset="none" type="overrides">
<para>You should override this method and use a conversion that sets the appropriate <see cref="P:System.Diagnostics.Switch.SwitchSetting" /> value for your switch.</para>
</block>
</Docs>
</Member>
<Member MemberName="SwitchSetting">
<MemberSignature Language="C#" Value="protected int SwitchSetting { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 SwitchSetting" />
<MemberSignature Language="DocId" Value="P:System.Diagnostics.Switch.SwitchSetting" />
<MemberSignature Language="VB.NET" Value="Protected Property SwitchSetting As Integer" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; property int SwitchSetting { int get(); void set(int value); };" />
<MemberSignature Language="F#" Value="member this.SwitchSetting : int with get, set" Usage="System.Diagnostics.Switch.SwitchSetting" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the current setting for this switch.</summary>
<value>The current setting for this switch. The default is zero.</value>
<remarks>To be added.</remarks>
<altmember cref="T:System.Diagnostics.Switch" />
<altmember cref="T:System.Diagnostics.BooleanSwitch" />
<altmember cref="T:System.Diagnostics.TraceSwitch" />
<altmember cref="T:System.Diagnostics.Debug" />
<altmember cref="T:System.Diagnostics.Trace" />
</Docs>
</Member>
<Member MemberName="Value">
<MemberSignature Language="C#" Value="protected string Value { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Value" />
<MemberSignature Language="DocId" Value="P:System.Diagnostics.Switch.Value" />
<MemberSignature Language="VB.NET" Value="Protected Property Value As String" />
<MemberSignature Language="C++ CLI" Value="protected:&#xA; property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };" />
<MemberSignature Language="F#" Value="member this.Value : string with get, set" Usage="System.Diagnostics.Switch.Value" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Diagnostics.TraceSource</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<AssemblyVersion>4.1.1.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the value of the switch.</summary>
<value>A string representing the value of the switch.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.Diagnostics.Switch.OnValueChanged%2A> method is called when the value of the <xref:System.Diagnostics.Switch.Value%2A> property is changed. The <xref:System.Diagnostics.Switch.OnValueChanged%2A> method parses the value of this property and converts it to an integer value, which is then used to set the <xref:System.Diagnostics.Switch.SwitchSetting%2A> property.
]]></format>
</remarks>
<exception cref="T:System.Configuration.ConfigurationErrorsException">The value is <see langword="null" />.
-or-
The value does not consist solely of an optional negative sign followed by a sequence of digits ranging from 0 to 9.
-or-
The value represents a number less than <see cref="F:System.Int32.MinValue" /> or greater than <see cref="F:System.Int32.MaxValue" />.</exception>
<block subset="none" type="overrides">
<para>You should override the <see cref="M:System.Diagnostics.Switch.OnValueChanged" /> method and provide a conversion operation that sets the appropriate <see cref="P:System.Diagnostics.Switch.SwitchSetting" /> value for your switch.</para>
</block>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.