The Labs \ Source Viewer \ SSCLI \ System.ComponentModel.Design.Serialization \ DesignerSerializerAttribute

  1. //------------------------------------------------------------------------------
  2. // <copyright file="DesignerSerializerAttribute.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. namespace System.ComponentModel.Design.Serialization
  16. {
  17.     using System.Security.Permissions;
  18.    
  19.     /// <devdoc>
  20.     /// This attribute can be placed on a class to indicate what serialization
  21.     /// object should be used to serialize the class at design time.
  22.     /// </devdoc>
  23.     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
  24.     public sealed class DesignerSerializerAttribute : Attribute
  25.     {
  26.         private string serializerTypeName;
  27.         private string serializerBaseTypeName;
  28.         private string typeId;
  29.        
  30.         /// <devdoc>
  31.         /// Creates a new designer serialization attribute.
  32.         /// </devdoc>
  33.         public DesignerSerializerAttribute(Type serializerType, Type baseSerializerType)
  34.         {
  35.             this.serializerTypeName = serializerType.AssemblyQualifiedName;
  36.             this.serializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
  37.         }
  38.        
  39.         /// <devdoc>
  40.         /// Creates a new designer serialization attribute.
  41.         /// </devdoc>
  42.         public DesignerSerializerAttribute(string serializerTypeName, Type baseSerializerType)
  43.         {
  44.             this.serializerTypeName = serializerTypeName;
  45.             this.serializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
  46.         }
  47.        
  48.         /// <devdoc>
  49.         /// Creates a new designer serialization attribute.
  50.         /// </devdoc>
  51.         public DesignerSerializerAttribute(string serializerTypeName, string baseSerializerTypeName)
  52.         {
  53.             this.serializerTypeName = serializerTypeName;
  54.             this.serializerBaseTypeName = baseSerializerTypeName;
  55.         }
  56.        
  57.         /// <devdoc>
  58.         /// Retrieves the fully qualified type name of the serializer.
  59.         /// </devdoc>
  60.         public string SerializerTypeName {
  61.             get { return serializerTypeName; }
  62.         }
  63.        
  64.         /// <devdoc>
  65.         /// Retrieves the fully qualified type name of the serializer base type.
  66.         /// </devdoc>
  67.         public string SerializerBaseTypeName {
  68.             get { return serializerBaseTypeName; }
  69.         }
  70.        
  71.         /// <internalonly/>
  72.         /// <devdoc>
  73.         /// <para>
  74.         /// This defines a unique ID for this attribute type. It is used
  75.         /// by filtering algorithms to identify two attributes that are
  76.         /// the same type. For most attributes, this just returns the
  77.         /// Type instance for the attribute. EditorAttribute overrides
  78.         /// this to include the type of the editor base type.
  79.         /// </para>
  80.         /// </devdoc>
  81.         public override object TypeId {
  82.             get {
  83.                 if (typeId == null) {
  84.                     string baseType = serializerBaseTypeName;
  85.                     int comma = baseType.IndexOf(',');
  86.                     if (comma != -1) {
  87.                         baseType = baseType.Substring(0, comma);
  88.                     }
  89.                     typeId = GetType().FullName + baseType;
  90.                 }
  91.                 return typeId;
  92.             }
  93.         }
  94.     }
  95. }

Developer Fusion