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

  1. /*=====================================================================
  2.   File:      LangConstructorInfo.cs
  3.  
  4.   Summary:   LangConstructorInfo implements or declares all of the 
  5.          functionality that is required of subclasses that re-
  6.          present constructors in a particular language.
  7.  
  8. ---------------------------------------------------------------------
  9.   This file is part of the Microsoft NGWS SDK Code Samples.
  10.  
  11.   Copyright (C) 2000 Microsoft Corporation.  All rights reserved.
  12.  
  13. This source code is intended only as a supplement to Microsoft
  14. Development Tools and/or on-line documentation.  See these other
  15. materials for detailed information regarding Microsoft code samples.
  16.  
  17. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  18. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  20. PARTICULAR PURPOSE.
  21. =====================================================================*/
  22.  
  23. namespace LangUtil {
  24.  
  25. using System;
  26. using System.Reflection;
  27. using System.Collections;
  28.  
  29.    public abstract class LangConstructorInfo : LangMember
  30.    {
  31.       // Internal data members that are loaded by the constructor.
  32.       // These fields contain the information necessary for children to 
  33.       // build accurate language-translations
  34.       protected String m_Name = String.Empty;
  35.       protected ArrayList m_Parameters = null;
  36.       protected ConstructorInfo m_ThisConstructorInfo = null;
  37.       protected Type m_ThisType =  null;
  38.       protected bool m_Overloads =  false;
  39.  
  40.       public LangConstructorInfo( ConstructorInfo myConstructor )
  41.       {
  42.          if ( myConstructor == null )
  43.             throw new NullReferenceException( "The ConstructorInfo passed to the constructor is null." );
  44.  
  45.          m_ThisConstructorInfo = myConstructor;
  46.          m_Name = myConstructor.Name;
  47.          m_ThisType = myConstructor.ReflectedType;
  48.  
  49.          // Initialize "m_Overloads" to true if there is more than 1 non-private constructor
  50.          
  51.          ConstructorInfo[] allConstructors = myConstructor.DeclaringType.GetConstructors( BindingFlags.LookupAll );
  52.          int cnt = 0;
  53.          for ( int i = 0; i < allConstructors.Length; i++ )
  54.          {
  55.             if ( !allConstructors[i].IsPrivate && allConstructors[i].Name.Equals( m_Name ) ) 
  56.                cnt++;
  57.          }
  58.          if ( cnt > 1 ) 
  59.             m_Overloads = true;
  60.  
  61.          // Determine whether method can accept variable-length arguments
  62.          if ( myConstructor.CallingConvention == CallingConventions.VarArgs )
  63.             m_VarArgs = true;
  64.  
  65.          // Obtain list of indexed properties
  66.           
  67.          ParameterInfo[] myParams = myConstructor.GetParameters();
  68.          m_Parameters = GetParamList( myParams );
  69.       }
  70.  
  71.       /*
  72.       // IsOverloaded returns a boolean indicating whether the constructor is overloaded. 
  73.       // In VisualBasicConstructorInfo, the declaration methods must put in "Overloaded",
  74.       // which requires a little dancing. See the Text- and HTMLDeclaration properties in 
  75.       // VisualBasicConstructorInfo.
  76.       */
  77.  
  78.       public bool IsOverloaded
  79.       {
  80.          get
  81.          {
  82.             return m_Overloads;
  83.          }
  84.       }
  85.  
  86.       /* 
  87.       // GetParamList must be overridden by subclasses to return an ArrayList of 
  88.       // LangMembers that represent particular languages. As a result, callers merely
  89.       // have to cast once to acquire the language-specific object.
  90.       */
  91.  
  92.       protected virtual ArrayList GetParamList( ParameterInfo[] ParamArray )
  93.       {
  94.          throw new NotSupportedException( "GetParamList not yet implemented on this class." );
  95.       }
  96.  
  97.       /* LangName can be overridden to provide a language-specific name for 
  98.       // the constructor. For example, the Visual Basic constructor name 
  99.       // is "New" rather than the name of the class or .ctor.
  100.       */
  101.  
  102.       // Note: Recall that Types may return []*& appended if this is called on a parameter
  103.       // or return type.
  104.  
  105.       public String LangName
  106.       {
  107.          virtual get
  108.          { 
  109.             return m_ThisConstructorInfo.ReflectedType.Name;
  110.          }
  111.       }
  112.  
  113.       public String Name
  114.       {
  115.          override get { return m_Name; }
  116.       }
  117.  
  118.       public ConstructorInfo ThisConstructorInfo
  119.       {
  120.          get { return m_ThisConstructorInfo; }
  121.       }
  122.  
  123.       public override bool IsConstructor()
  124.       {
  125.          return true;
  126.       }
  127.    }
  128.  
  129. } // namespace LangUtil
  130.