The Labs \ Source Viewer \ SSCLI \ System.Diagnostics \ SourceSwitch

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SourceSwitch.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Collections;
  17. using System.Collections.Specialized;
  18. using System.Threading;
  19. using System.Security;
  20. using System.Security.Permissions;
  21. namespace System.Diagnostics
  22. {
  23.     public class SourceSwitch : Switch
  24.     {
  25.         public SourceSwitch(string name) : base(name, String.Empty)
  26.         {
  27.         }
  28.        
  29.         public SourceSwitch(string displayName, string defaultSwitchValue) : base(displayName, String.Empty, defaultSwitchValue)
  30.         {
  31.         }
  32.        
  33.         public SourceLevels Level {
  34.             get { return (SourceLevels)SwitchSetting; }
  35.             [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  36.             set { SwitchSetting = (int)value; }
  37.         }
  38.        
  39.         public bool ShouldTrace(TraceEventType eventType)
  40.         {
  41.             return (SwitchSetting & (int)eventType) != 0;
  42.         }
  43.        
  44.         protected override void OnValueChanged()
  45.         {
  46.             SwitchSetting = (int)Enum.Parse(typeof(SourceLevels), Value, true);
  47.         }
  48.     }
  49. }

Developer Fusion