home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: LangMethodInfo.cs
-
- Summary: LangMethodInfo implements or declares the functionality common
- to subclasses that represent specific languages.
-
- ---------------------------------------------------------------------
- This file is part of the Microsoft NGWS SDK Code Samples.
-
- Copyright (C) 2000 Microsoft Corporation. All rights reserved.
-
- This source code is intended only as a supplement to Microsoft
- Development Tools and/or on-line documentation. See these other
- materials for detailed information regarding Microsoft code samples.
-
- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- PARTICULAR PURPOSE.
- =====================================================================*/
-
- namespace LangUtil {
-
- using System;
- using System.Reflection;
- using System.Collections;
-
- public abstract class LangMethodInfo : LangMember
- {
- // Internal fields containing information necessary for subclasses
- // to construct the proper language-specific declarations.
-
- protected bool m_Overloads = false;
- protected String m_Name = String.Empty;
- protected MethodInfo m_ThisMethodInfo = null;
- protected ArrayList m_Parameters = null;
-
- public LangMethodInfo( MethodInfo myMethod )
- {
- if ( myMethod == null )
- throw new NullReferenceException( "The MethodInfo passed to the constructor is null." );
-
- // Determine method name and return type
- m_Name = myMethod.Name;
- m_ThisMethodInfo = myMethod;
-
- // Initialize "m_Overloads" to true if there is more than 1 non-private constructor
-
- MethodInfo[] allMethods = myMethod.DeclaringType.GetMethods( BindingFlags.LookupAll );
- int cnt = 0;
- for ( int i = 0; i < allMethods.Length; i++ )
- {
- if ( !allMethods[i].IsPrivate && allMethods[i].Name.Equals( m_Name ) )
- cnt++;
- }
- if ( cnt > 1 )
- m_Overloads = true;
-
- // Determine whether method can accept variable-length arguments
- if ( myMethod.CallingConvention == CallingConventions.VarArgs )
- m_VarArgs = true;
-
- // Obtain parameter details
- ParameterInfo[] myParams = myMethod.GetParameters();
- m_Parameters = GetParamList( myParams );
- }
-
- /*
- // IsOverloaded returns a boolean indicating whether the constructor is overloaded.
- // In VisualBasicConstructorInfo, the declaration methods must put in "Overloaded",
- // which requires a little dancing. See the Text- and HTMLDeclaration properties in
- // VisualBasicConstructorInfo.
- */
-
- public bool IsOverloaded
- {
- get
- {
- return m_Overloads;
- }
- }
-
- /* ReturnLangType must be implemented on children to return the appropriate language type.
- // It is merely declared here for specification purposes; it must be implemented on
- // subclasses so that the caller does not have to cast back before use.
-
- public <LanguageName>LangType ReturnLangType
- {
- abstract get;
- }
-
- */
-
-
- /*
- // GetParamList overrides LangMember.GetParamList to throw an exception.
- // Subclasses must implement this to return an ArrayList of classes
- // that are that specific language type.
- */
-
- protected virtual ArrayList GetParamList( ParameterInfo[] ParamArray )
- {
- throw new NotSupportedException( "GetParamList not yet implemented on this class." );
- }
-
- public String Name
- {
- override get { return m_Name; }
- }
-
- public MethodInfo ThisMethodInfo
- {
- get { return m_ThisMethodInfo; }
- }
-
- // Note: Recall that ReflectedType may be IsPointer, IsArray, or IsByRef if
- // it is a ParameterType or ReturnType.
-
- public Type ThisType
- {
- override get { return m_ThisMethodInfo.ReflectedType; }
- }
-
- /* Parameters property returns the internal variable which should be loaded by
- // the subclasses' constructor. The return value should be an ArrayList of
- // language-specific <languagename>MethodInfo types.
- */
-
- public ArrayList Parameters
- {
- get { return m_Parameters; }
- }
-
- public override bool IsMethod()
- {
- return true;
- }
- }
-
- } // namespace LangUtil
-
-