2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System / System.Diagnostics / TraceSwitch.cs
blob82c82d35ec5b39f0137a21e16a21b0a2ef57269c
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)
11 // (C) 2001-2002
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.
35 namespace System.Diagnostics
37 #if NET_2_0
38 [SwitchLevel (typeof (TraceLevel))]
39 #endif
40 public class TraceSwitch : Switch
42 public TraceSwitch(string displayName, string description)
43 : base(displayName, description)
47 #if NET_2_0
48 public TraceSwitch(string displayName, string description, string defaultSwitchValue)
49 : base(displayName, description)
51 Value = defaultSwitchValue;
53 #endif
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;
64 public bool TraceError {
65 get {return SwitchSetting >= (int) TraceLevel.Error;}
68 public bool TraceWarning {
69 get {return SwitchSetting >= (int) TraceLevel.Warning;}
72 public bool TraceInfo {
73 get {return SwitchSetting >= (int) TraceLevel.Info;}
76 public bool TraceVerbose {
77 get {return SwitchSetting >= (int) TraceLevel.Verbose;}
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()
87 if (SwitchSetting < 0)
88 SwitchSetting = (int) TraceLevel.Off;
89 else if (SwitchSetting > 4)
90 SwitchSetting = (int) TraceLevel.Verbose;
93 #if NET_2_0
94 protected override void OnValueChanged ()
96 SwitchSetting = (int) Enum.Parse (typeof (TraceLevel),
97 Value, true);
99 #endif