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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="TypedElement.cs" company="Microsoft Corporation">
  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.Configuration;
  16. using System;
  17. using System.Reflection;
  18. using System.Globalization;
  19. namespace System.Diagnostics
  20. {
  21.     internal class TypedElement : ConfigurationElement
  22.     {
  23.         protected static readonly ConfigurationProperty _propTypeName = new ConfigurationProperty("type", typeof(string), String.Empty, ConfigurationPropertyOptions.IsRequired);
  24.         protected static readonly ConfigurationProperty _propInitData = new ConfigurationProperty("initializeData", typeof(string), String.Empty, ConfigurationPropertyOptions.None);
  25.        
  26.         protected ConfigurationPropertyCollection _properties;
  27.         protected object _runtimeObject = null;
  28.         private Type _baseType;
  29.        
  30.         public TypedElement(Type baseType) : base()
  31.         {
  32.             _properties = new ConfigurationPropertyCollection();
  33.             _properties.Add(_propTypeName);
  34.             _properties.Add(_propInitData);
  35.            
  36.             _baseType = baseType;
  37.         }
  38.        
  39.         [ConfigurationProperty("initializeData", DefaultValue = "")]
  40.         public string InitData {
  41.             get { return (string)this[_propInitData]; }
  42.             // This is useful when the OM becomes public. In the meantime, this can be utilized via reflection
  43.             set { this[_propInitData] = value; }
  44.         }
  45.        
  46.        
  47.         protected override ConfigurationPropertyCollection Properties {
  48.             get { return _properties; }
  49.         }
  50.        
  51.         [ConfigurationProperty("type", IsRequired = true, DefaultValue = "")]
  52.         public virtual string TypeName {
  53.             get { return (string)this[_propTypeName]; }
  54.             set { this[_propTypeName] = value; }
  55.         }
  56.        
  57.         protected object BaseGetRuntimeObject()
  58.         {
  59.             if (_runtimeObject == null)
  60.                 _runtimeObject = TraceUtils.GetRuntimeObject(TypeName, _baseType, InitData);
  61.            
  62.             return _runtimeObject;
  63.         }
  64.        
  65.     }
  66. }

Developer Fusion