1 //------------------------------------------------------------------------------
2 // <copyright file="BooleanSwitch.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
10 namespace System.Diagnostics {
11 using System.Diagnostics;
13 using System.Security;
14 using System.Security.Permissions;
17 /// <para>Provides a simple on/off switch that can be used to control debugging and tracing
20 [SwitchLevel(typeof(bool))]
21 public class BooleanSwitch : Switch {
23 /// <para>Initializes a new instance of the <see cref='System.Diagnostics.BooleanSwitch'/>
26 public BooleanSwitch(string displayName, string description)
27 : base(displayName, description) {
30 public BooleanSwitch(string displayName, string description, string defaultSwitchValue)
31 : base(displayName, description, defaultSwitchValue) { }
34 /// <para>Specifies whether the switch is enabled
35 /// (<see langword='true'/>) or disabled (<see langword='false'/>).</para>
39 return (SwitchSetting == 0) ? false : true;
41 [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)]
43 SwitchSetting = value ? 1 : 0;
47 protected override void OnValueChanged() {
49 if (Boolean.TryParse(Value, out b))
50 SwitchSetting = ( b ? 1 : 0);
52 base.OnValueChanged();