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

  1. /*=====================================================================
  2.   File:      LangMethodInfo.cs
  3.  
  4.   Summary:   LangMethodInfo implements or declares the functionality common
  5.          to subclasses that represent specific languages.
  6.  
  7. ---------------------------------------------------------------------
  8.   This file is part of the Microsoft NGWS SDK Code Samples.
  9.  
  10.   Copyright (C) 2000 Microsoft Corporation.  All rights reserved.
  11.  
  12. This source code is intended only as a supplement to Microsoft
  13. Development Tools and/or on-line documentation.  See these other
  14. materials for detailed information regarding Microsoft code samples.
  15.  
  16. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  17. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  19. PARTICULAR PURPOSE.
  20. =====================================================================*/
  21.  
  22. namespace LangUtil {
  23.  
  24. using System;
  25. using System.Reflection;
  26. using System.Collections;
  27.  
  28.    public abstract class LangMethodInfo : LangMember
  29.    {      
  30.       // Internal fields containing information necessary for subclasses
  31.       // to construct the proper language-specific declarations.
  32.  
  33.       protected bool m_Overloads = false;
  34.       protected String m_Name = String.Empty;
  35.       protected MethodInfo m_ThisMethodInfo = null;
  36.       protected ArrayList m_Parameters = null;
  37.  
  38.       public LangMethodInfo( MethodInfo myMethod )
  39.       {
  40.          if ( myMethod == null )
  41.             throw new NullReferenceException( "The MethodInfo passed to the constructor is null." );
  42.  
  43.          // Determine method name and return type
  44.          m_Name = myMethod.Name;
  45.          m_ThisMethodInfo = myMethod;
  46.  
  47.          // Initialize "m_Overloads" to true if there is more than 1 non-private constructor
  48.          
  49.          MethodInfo[] allMethods = myMethod.DeclaringType.GetMethods( BindingFlags.LookupAll );
  50.          int cnt = 0;
  51.          for ( int i = 0; i < allMethods.Length; i++ )
  52.          {
  53.             if ( !allMethods[i].IsPrivate && allMethods[i].Name.Equals( m_Name ) )
  54.                cnt++;
  55.          }
  56.          if ( cnt > 1 ) 
  57.             m_Overloads = true;
  58.  
  59.          // Determine whether method can accept variable-length arguments
  60.          if ( myMethod.CallingConvention == CallingConventions.VarArgs )
  61.             m_VarArgs = true;
  62.  
  63.          // Obtain parameter details
  64.          ParameterInfo[] myParams = myMethod.GetParameters();
  65.          m_Parameters = GetParamList( myParams );
  66.       }
  67.  
  68.       /*
  69.       // IsOverloaded returns a boolean indicating whether the constructor is overloaded. 
  70.       // In VisualBasicConstructorInfo, the declaration methods must put in "Overloaded",
  71.       // which requires a little dancing. See the Text- and HTMLDeclaration properties in 
  72.       // VisualBasicConstructorInfo.
  73.       */
  74.  
  75.       public bool IsOverloaded
  76.       {
  77.          get
  78.          {
  79.             return m_Overloads;
  80.          }
  81.       }
  82.  
  83.       /* ReturnLangType must be implemented on children to return the appropriate language type.
  84.       // It is merely declared here for specification purposes; it must be implemented on 
  85.       // subclasses so that the caller does not have to cast back before use. 
  86.  
  87.       public <LanguageName>LangType ReturnLangType
  88.       {
  89.          abstract get;
  90.       }
  91.  
  92.       */
  93.  
  94.  
  95.       /* 
  96.       // GetParamList overrides LangMember.GetParamList to throw an exception. 
  97.       // Subclasses must implement this to return an ArrayList of classes 
  98.       // that are that specific language type.
  99.       */
  100.  
  101.       protected virtual ArrayList GetParamList( ParameterInfo[] ParamArray )
  102.       {
  103.          throw new NotSupportedException( "GetParamList not yet implemented on this class." );
  104.       }
  105.  
  106.       public String Name
  107.       {
  108.          override get { return m_Name; }
  109.       }
  110.  
  111.       public MethodInfo ThisMethodInfo
  112.       {
  113.          get { return m_ThisMethodInfo; }
  114.       }
  115.  
  116.       // Note: Recall that ReflectedType may be IsPointer, IsArray, or IsByRef if
  117.       // it is a ParameterType or ReturnType.
  118.  
  119.       public Type ThisType
  120.       {
  121.          override get { return m_ThisMethodInfo.ReflectedType; }      
  122.       }
  123.  
  124.       /* Parameters property returns the internal variable which should be loaded by 
  125.       // the subclasses' constructor. The return value should be an ArrayList of 
  126.       // language-specific <languagename>MethodInfo types.
  127.       */
  128.  
  129.       public ArrayList Parameters
  130.       {
  131.          get { return m_Parameters; }
  132.       }
  133.  
  134.       public override bool IsMethod()
  135.       {
  136.          return true;
  137.       }
  138.    }
  139.  
  140. } // namespace LangUtil
  141.  
  142.