System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / System / System.Diagnostics / TraceSwitch.cs
1 //
2 // System.Diagnostics.TraceSwtich.cs
3 //
4 // Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation 
5 // can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
6 //
7 // Author:
8 //      John R. Hicks (angryjohn69@nc.rr.com)
9 //      Jonathan Pryor (jonpryor@vt.edu)
10 //
11 // (C) 2001-2002
12 //
13
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 namespace System.Diagnostics
36 {
37 #if NET_2_0
38         [SwitchLevel (typeof (TraceLevel))]
39 #endif
40         public class TraceSwitch : Switch
41         {
42                 public TraceSwitch(string displayName, string description)
43                         : base(displayName, description)
44                 {
45                 }
46
47 #if NET_2_0
48                 public TraceSwitch(string displayName, string description, string defaultSwitchValue)
49                         : base(displayName, description)
50                 {
51                         Value = defaultSwitchValue;
52                 }
53 #endif
54
55                 public TraceLevel Level {
56                         get {return (TraceLevel) SwitchSetting;}
57                         set {
58                                 if (!Enum.IsDefined (typeof(TraceLevel), value))
59                                         throw new ArgumentException ("value");
60                                 SwitchSetting = (int) value;
61                         }
62                 }
63
64                 public bool TraceError {
65                         get {return SwitchSetting >= (int) TraceLevel.Error;}
66                 }
67
68                 public bool TraceWarning {
69                         get {return SwitchSetting >= (int) TraceLevel.Warning;}
70                 }
71
72                 public bool TraceInfo {
73                         get {return SwitchSetting >= (int) TraceLevel.Info;}
74                 }
75
76                 public bool TraceVerbose {
77                         get {return SwitchSetting >= (int) TraceLevel.Verbose;}
78                 }
79
80                 // .NET accepts values over 4; they're equivalent to TraceLevel.Verbose
81                 // For -1, .NET crashes.  (Oops!)  Other negative numbers work with an
82                 // equivalent to setting SwitchSetting to TraceLevel.Off.
83                 // The logic for the accessors will cope with values >= 4, so we'll just
84                 // check for negative numbers.
85                 protected override void OnSwitchSettingChanged()
86                 {
87                         if (SwitchSetting < 0)
88                                 SwitchSetting = (int) TraceLevel.Off;
89                         else if (SwitchSetting > 4)
90                                 SwitchSetting = (int) TraceLevel.Verbose;
91                 }
92
93 #if NET_2_0
94                 protected override void OnValueChanged ()
95                 {
96                         SwitchSetting = (int) Enum.Parse (typeof (TraceLevel),
97                                 Value, true);
98                 }
99 #endif
100         }
101 }
102