2 // System.Diagnostics.Switch.cs
4 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
5 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
8 // John R. Hicks (angryjohn69@nc.rr.com)
9 // Jonathan Pryor (jonpryor@vt.edu)
14 using System.Collections;
16 namespace System.Diagnostics
18 public abstract class Switch
20 private string name = "";
21 private string description = "";
22 private int switchSetting = 0;
24 // MS Behavior is that (quoting from MSDN for OnSwitchSettingChanged()):
25 // "...It is invoked the first time a switch reads its value from the
26 // configuration file..."
27 // The docs + testing implies two things:
28 // 1. The value of the switch is not read in from the constructor
29 // 2. The value is instead read in on the first time get_SwitchSetting is
31 // Assuming that OnSwitchSettingChanged() is invoked on a .config file
32 // read and on all changes
34 // Thus, we need to keep track of whether or not switchSetting has been
35 // initialized. Using `switchSetting=-1' seems logical, but if someone
36 // actually wants to use -1 as a switch value that would cause problems.
37 private bool initialized = false;
39 protected Switch(string displayName, string description)
41 this.name = displayName;
42 this.description = description;
45 public string Description {
46 get {return description;}
49 public string DisplayName {
53 protected int SwitchSetting {
57 GetConfigFileSetting ();
58 OnSwitchSettingChanged ();
63 if(switchSetting != value) {
64 switchSetting = value;
65 OnSwitchSettingChanged();
71 private void GetConfigFileSetting ()
73 // Load up the specified switch
75 (IDictionary) DiagnosticsConfiguration.Settings ["switches"];
79 switchSetting = int.Parse (o.ToString());
87 protected virtual void OnSwitchSettingChanged()
89 // Do nothing. This is merely provided for derived classes to know when
90 // the value of SwitchSetting has changed.