The Labs \ Source Viewer \ SSCLI \ System.CodeDom \ CodeAttributeDeclaration

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CodeAttributeDeclaration.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.CodeDom
  16. {
  17.    
  18.     using System.Diagnostics;
  19.     using System;
  20.     using Microsoft.Win32;
  21.     using System.Collections;
  22.     using System.Runtime.InteropServices;
  23.     using System.Runtime.Serialization;
  24.    
  25.     /// <devdoc>
  26.     /// <para>
  27.     /// Represents a single custom attribute.
  28.     /// </para>
  29.     /// </devdoc>
  30.     [ClassInterface(ClassInterfaceType.AutoDispatch), ComVisible(true), Serializable()]
  31.     public class CodeAttributeDeclaration
  32.     {
  33.         private string name;
  34.         private CodeAttributeArgumentCollection arguments = new CodeAttributeArgumentCollection();
  35.         [OptionalField()]
  36.         private CodeTypeReference attributeType;
  37.        
  38.         /// <devdoc>
  39.         /// <para>
  40.         /// Initializes a new instance of <see cref='System.CodeDom.CodeAttributeDeclaration'/>.
  41.         /// </para>
  42.         /// </devdoc>
  43.         public CodeAttributeDeclaration()
  44.         {
  45.         }
  46.        
  47.         /// <devdoc>
  48.         /// <para>
  49.         /// Initializes a new instance of <see cref='System.CodeDom.CodeAttributeDeclaration'/> using the specified name.
  50.         /// </para>
  51.         /// </devdoc>
  52.         public CodeAttributeDeclaration(string name)
  53.         {
  54.             Name = name;
  55.         }
  56.        
  57.         /// <devdoc>
  58.         /// <para>
  59.         /// Initializes a new instance of <see cref='System.CodeDom.CodeAttributeDeclaration'/> using the specified
  60.         /// arguments.
  61.         /// </para>
  62.         /// </devdoc>
  63.         public CodeAttributeDeclaration(string name, params CodeAttributeArgument[] arguments)
  64.         {
  65.             Name = name;
  66.             Arguments.AddRange(arguments);
  67.         }
  68.        
  69.         public CodeAttributeDeclaration(CodeTypeReference attributeType) : this(attributeType, null)
  70.         {
  71.         }
  72.        
  73.         public CodeAttributeDeclaration(CodeTypeReference attributeType, params CodeAttributeArgument[] arguments)
  74.         {
  75.             this.attributeType = attributeType;
  76.             if (attributeType != null) {
  77.                 this.name = attributeType.BaseType;
  78.             }
  79.            
  80.             if (arguments != null) {
  81.                 Arguments.AddRange(arguments);
  82.             }
  83.         }
  84.        
  85.         /// <devdoc>
  86.         /// <para>
  87.         /// The name of the attribute being declared.
  88.         /// </para>
  89.         /// </devdoc>
  90.         public string Name {
  91.             get { return (name == null) ? string.Empty : name; }
  92.             set {
  93.                 name = value;
  94.                 attributeType = new CodeTypeReference(name);
  95.             }
  96.         }
  97.        
  98.         /// <devdoc>
  99.         /// <para>
  100.         /// The arguments for the attribute.
  101.         /// </para>
  102.         /// </devdoc>
  103.         public CodeAttributeArgumentCollection Arguments {
  104.             get { return arguments; }
  105.         }
  106.        
  107.         public CodeTypeReference AttributeType {
  108.             get { return attributeType; }
  109.         }
  110.     }
  111. }

Developer Fusion