home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: NativeMethodInfo.cs
-
- Summary: For language-neutral reflection information.
-
- ---------------------------------------------------------------------
- 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.Text;
- using System.Reflection;
- using System.Collections;
-
- public class NativeMethodInfo : LangMember
- {
- internal String m_Name = String.Empty;
- internal MethodInfo m_ThisMethodInfo = null;
- internal NativeLangType m_ReturnLangType = null;
- internal ArrayList m_Parameters = null;
-
- public NativeMethodInfo( 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;
- m_ReturnLangType = new NativeLangType( myMethod.ReturnType );
-
- // Obtain parameter details
- ParameterInfo [] myParams = myMethod.GetParameters();
-
- // Determine whether method can accept variable-length arguments
- if ( myMethod.CallingConvention == CallingConventions.VarArgs )
- m_VarArgs = true;
-
- // Set arraylist size
- m_Parameters = new ArrayList( myParams.Length );
-
- for ( int x = 0; x < myParams.Length; x++ )
- {
- m_Parameters.Add( new NativeLangType( myParams[x] ) );
- }
- }
-
- public bool IsOverloaded
- {
- get
- {
- MethodInfo[] allMethods = m_ThisMethodInfo.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 )
- return true;
- else
- return false;
- }
- }
-
- public Type ThisType
- {
- override get { return m_ThisMethodInfo.ReflectedType; }
- }
-
- public String Name
- {
- override get { return m_Name; }
- }
-
- public MethodInfo ThisMethodInfo
- {
- get { return m_ThisMethodInfo; }
- }
-
- public NativeLangType ReturnLangType
- {
- get { return m_ReturnLangType; }
- }
-
- public ArrayList Parameters
- {
- get { return m_Parameters; }
- }
-
- public VisualBasicMethodInfo VisualBasicLangObject
- {
- get { return new VisualBasicMethodInfo( m_ThisMethodInfo ); }
- }
-
- public CSharpMethodInfo CSharpLangObject
- {
- get { return new CSharpMethodInfo( m_ThisMethodInfo ); }
- }
-
- public MCMethodInfo MCLangObject
- {
- get { return new MCMethodInfo( m_ThisMethodInfo ); }
- }
-
- public string Attributes
- {
- override get
- {
- throw new Exception( "NativeMethodInfo.NativeAttributes has not yet been implemented." );
-
- }
- }
-
- public String TextDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( this.Attributes );
-
- Syntax.Append( m_ReturnLangType.ClassName + " " + m_Name + "(" );
-
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- if ( ( (NativeLangType)m_Parameters[i] ).IsByRef )
- Syntax.Append( "ref " );
- Syntax.Append( ( (NativeLangType)m_Parameters[i] ).ClassName );
- Syntax.Append( " " );
- Syntax.Append( ( (NativeLangType)m_Parameters[i] ).ParamVarName );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- {
- // If there's varargs
- if ( VarArgs )
- {
- Syntax.Append( ", " );
- Syntax.Append( "..." );
- }
- }
- }
- Syntax.Append( ");" );
- return Syntax.ToString();
- }
- }
-
- public String HTMLDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\">" );
- Syntax.Append( "<span style=\"color:red\">[CSharp]</span><BR><B>" );
- Syntax.Append( this.Attributes );
-
- Syntax.Append( ( (NativeLangType)m_ReturnLangType ).ClassName + " " + m_Name + "(" );
-
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- Syntax.Append( "<BR> " );
- if ( ( (NativeLangType)m_Parameters[i] ).IsByRef )
- Syntax.Append( "ref " );
- Syntax.Append( ( (NativeLangType)m_Parameters[i] ).ClassName );
- Syntax.Append( " <I>" + ( (NativeLangType)m_Parameters[i] ).ParamVarName + "</I>" );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- {
- // If there's varargs
- if ( VarArgs )
- {
- Syntax.Append( ", <BR/> ..." );
- }
- Syntax.Append( "<BR/>" );
- }
- }
- Syntax.Append( ");</B></PRE>" );
- return Syntax.ToString();
- }
- }
-
- public override bool IsMethod()
- {
- return true;
- }
- }
-
- } // namespace LangUtil
-