home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / ClsView / LangMember.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.7 KB  |  167 lines

  1. /*=====================================================================
  2.   File:      LangMember.cs
  3.  
  4.   Summary:   LangMember declares or implements all the functionality
  5.          generic to subclasses. These include returning attributes
  6.          on the member, returning the name of the member, lang-based
  7.          strings such as member attributes, and the declaration 
  8.          strings that all members must override.
  9.  
  10. ---------------------------------------------------------------------
  11.   This file is part of the Microsoft NGWS SDK Code Samples.
  12.  
  13.   Copyright (C) 2000 Microsoft Corporation.  All rights reserved.
  14.  
  15. This source code is intended only as a supplement to Microsoft
  16. Development Tools and/or on-line documentation.  See these other
  17. materials for detailed information regarding Microsoft code samples.
  18.  
  19. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  20. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  22. PARTICULAR PURPOSE.
  23. =====================================================================*/
  24.  
  25. namespace LangUtil {
  26.  
  27. using System;
  28. using System.Text;
  29. using System.Reflection;
  30.  
  31.    public abstract class LangMember
  32.    {
  33.       protected bool m_VarArgs = false;
  34.  
  35.       public LangMember()
  36.       {
  37.       }
  38.  
  39.       /*
  40.       // GetAttributeArray takes an ICustomAttributeProvider, which is implemented by MemberInfo,
  41.       // and returns an array of objects that represent each attribute that is defined on the
  42.       // member.
  43.       */
  44.  
  45.       public virtual Object[] GetAttributeArray( ICustomAttributeProvider MemInfo )
  46.       {
  47.          MemberInfo c_cap;
  48.          try
  49.          {
  50.             c_cap = (MemberInfo)MemInfo;
  51.          }
  52.          catch ( Exception Ex )
  53.          {
  54.             throw new InvalidCastException( "c_cap can't be cast to MemberInfo.", Ex );
  55.          }  
  56.          if ( c_cap == null ) 
  57.             throw new ArgumentException( "MemberInfo passed to GetAttributeArray was null." );
  58.          
  59.          return c_cap.GetCustomAttributes();
  60.       }
  61.  
  62.       /*    Remove the comments around this method when possible.
  63.             public bool IsOverridden{
  64.                abstract get;
  65.             }
  66.       */
  67.  
  68.       public virtual bool IsProperty()
  69.       {
  70.          return false;
  71.       }
  72.  
  73.       public virtual bool IsMethod()
  74.       {
  75.          return false;
  76.       }
  77.  
  78.       public virtual bool IsConstructor()
  79.       {
  80.          return false;
  81.       }
  82.  
  83.       public virtual bool IsField()
  84.       {
  85.          return false;
  86.       }
  87.  
  88.       public virtual bool IsEvent()
  89.       {
  90.          return false;
  91.       }
  92.  
  93.       /* ThisType will always be the Type object that implements or defines the member
  94.       // that the caller is currently reflecting upon.
  95.       //
  96.       */
  97.  
  98.       public Type ThisType
  99.       {
  100.          abstract get;
  101.       }
  102.    
  103.       public String Attributes
  104.       {
  105.          abstract get;
  106.       }
  107.  
  108.       public string Name
  109.       {
  110.          abstract get;
  111.       }
  112.       
  113.       public bool VarArgs
  114.       {
  115.          get { return false; } // m_VarArgs; Temporary disable the varargs
  116.       }
  117.  
  118.       /*
  119.       // The <FORMAT>Declaration properties must be overridden by children to return a string that 
  120.       // is a valid declaration in the language that the child class represents.
  121.       */
  122.  
  123.       public string TextDeclaration
  124.       {
  125.          virtual get
  126.          {
  127.             throw new NotSupportedException( "TextDeclaration has not yet been implemented on this class." );
  128.          }
  129.       }
  130.  
  131.       public string HTMLDeclaration
  132.       {
  133.          virtual get
  134.          {
  135.             throw new NotSupportedException( "HTMLDeclaration has not yet been implemented on this class." );
  136.          }
  137.       }
  138.  
  139.       public string XMLDeclaration
  140.       {
  141.          virtual get
  142.          {
  143.             throw new NotSupportedException( "XMLDeclaration has not yet been implemented on this class." );
  144.          }
  145.       }
  146.  
  147.       // In here for meteor's use. Remove later.
  148.       protected string MakeXRef( Type ThisType, string LangBasedClassName )
  149.       {
  150.          StringBuilder XREF = new StringBuilder( 200 );
  151.          XREF.Append( "<XRef type=\"" );
  152.          if ( ThisType.IsInterface )
  153.             XREF.Append( "Interface\" " );
  154.          else if ( ThisType.IsValueType )
  155.             XREF.Append( "ValueType\" " );
  156.          else if ( !ThisType.IsInterface && !ThisType.IsValueType )
  157.             XREF.Append( "Class\" " );
  158.          XREF.Append( "name=\"" + ThisType.FullName + "\">" );
  159.          XREF.Append( LangBasedClassName );
  160.          XREF.Append( "</XRef>" );
  161.          return XREF.ToString();
  162.       }
  163.    }
  164.  
  165. } // namespace LangUtil
  166.  
  167.