home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: VisualBasicMethodInfo.cs
-
- Summary: Brief summary of the file contents and purpose.
-
- ---------------------------------------------------------------------
- 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 VisualBasicMethodInfo : LangMember
- {
- internal string m_Name = String.Empty;
- internal MethodInfo m_ThisMethodInfo = null;
- internal VisualBasicLangType m_ReturnLangType = null;
- internal ArrayList m_Parameters = null;
-
- public VisualBasicMethodInfo( 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 VisualBasicLangType( myMethod.ReturnType );
-
- // Determine whether method can accept variable-length arguments
- if ( myMethod.CallingConvention == CallingConventions.VarArgs )
- m_VarArgs = true;
-
- // Obtain parameter details
- ParameterInfo[] myParams = myMethod.GetParameters();
-
- // Set arraylist size
- m_Parameters = new ArrayList( myParams.Length );
-
- for ( int x = 0; x < myParams.Length; x++ )
- {
- m_Parameters.Add( new VisualBasicLangType( myParams[x] ) );
- }
- }
-
- public MethodInfo ThisMethodInfo
- {
- get { return m_ThisMethodInfo; }
- }
-
- public bool IsOverloaded
- {
- get
- {
- MethodInfo[] allMethods = m_ThisMethodInfo.DeclaringType.GetMethods( BindingFlags.NonPublic );
- 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 VisualBasicLangType ReturnLangType
- {
- get { return m_ReturnLangType; }
- }
-
- public ArrayList Parameters
- {
- get { return m_Parameters; }
- }
-
- public Type ThisType
- {
- override get { return m_ThisMethodInfo.ReflectedType; }
- }
-
- public string Name
- {
- override get { return m_Name; }
- }
-
- public string Attributes
- {
- override get
- {
- StringBuilder sb = new StringBuilder();
- if ( m_ThisMethodInfo.IsAbstract )
- sb.Append( "MustOverride " );
-
- if ( m_ThisMethodInfo.IsFinal && !m_ThisMethodInfo.DeclaringType.IsSealed &&
- !m_ThisMethodInfo.DeclaringType.IsInterface )
- sb.Append( "CantOverride " );
-
- try
- {
- m_ThisMethodInfo.ReflectedType.GetMethod( m_ThisMethodInfo.Name );
- }
- catch
- {
- sb.Append( "Overloads " );
- }
-
- if ( m_ThisMethodInfo.IsPublic )
- sb.Append( "Public " );
- else if ( m_ThisMethodInfo.IsPrivate )
- sb.Append( "Private " );
- else if ( m_ThisMethodInfo.IsFamily )
- sb.Append( "Protected " );
- else if ( m_ThisMethodInfo.IsAssembly )
- sb.Append( "Assembly " );
- else if ( m_ThisMethodInfo.IsFamilyAndAssembly )
- sb.Append( "FamilyAndAssembly " );
- else if ( m_ThisMethodInfo.IsFamilyOrAssembly )
- sb.Append( "FamilyOrAssembly " );
-
- if ( m_ThisMethodInfo.IsStatic )
- sb.Append( "Shared " );
-
- if ( m_ThisMethodInfo.ReturnType == typeof( Void ) )
- sb.Append( "Sub " );
- else
- sb.Append( "Function " );
-
- return sb.ToString();
- }
- }
-
- public string ShortTextDeclaration
- {
- get
- {
- StringBuilder Syntax = new StringBuilder( m_Name + "(" );
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- Syntax.Append( ( (VisualBasicLangType)m_Parameters[i] ).ClassName );
-
- if ( ( (VisualBasicLangType)m_Parameters[i] ).IsRealArray )
- Syntax.Append( "()" );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- {
- }
- }
- Syntax.Append( ")" );
- return Syntax.ToString();
- }
- }
-
- public string TextDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( Attributes );
- Syntax.Append( m_Name );
- Syntax.Append( "(" );
-
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- if ( ( (VisualBasicLangType)m_Parameters[i] ).m_IsByRef )
- Syntax.Append( "ByRef " );
- else
- Syntax.Append( "ByVal " );
-
- string strClassName = ( (VisualBasicLangType)m_Parameters[i] ).ClassName;
- // Strip the brackets here, if any
- bool bBrackets = false;
- if ( strClassName.Substring( strClassName.Length - 2 ) == "[]" )
- {
- bBrackets = true;
- strClassName = strClassName.Substring( 0, strClassName.Length - 2 );
- }
-
- Syntax.Append( ( (VisualBasicLangType)m_Parameters[i] ).ParamVarName );
-
- if ( bBrackets || ( (VisualBasicLangType)m_Parameters[i] ).IsRealArray )
- Syntax.Append( "()" );
-
- Syntax.Append( " As " + strClassName );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- {
- // If there's varargs do the right thing, then finish the syntax block
- if ( VarArgs )
- Syntax.Append( ", ..." );
- }
- }
-
- Syntax.Append( ")" );
-
- if ( !m_ReturnLangType.ClassName.Equals( "Void" ) )
- {
- Syntax.Append( " As " );
- if ( m_ReturnLangType.m_IsByRef )
- Syntax.Append( "ByRef " );
- Syntax.Append( m_ReturnLangType.ClassName );
- if ( m_ReturnLangType.IsRealArray )
- Syntax.Append( "()" );
- }
- return Syntax.ToString();
- }
- }
-
- public string HTMLDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\">" );
- Syntax.Append( "<span style=\"color:red\">[Visual Basic]</span><BR><B>" );
-
- Syntax.Append( Attributes );
- Syntax.Append( m_Name );
- Syntax.Append( "(" );
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- Syntax.Append( " _" );
- Syntax.Append( "<BR> " );
- if ( ( (VisualBasicLangType)m_Parameters[i]).IsByRef )
- Syntax.Append( "ByRef " );
- else
- Syntax.Append( "ByVal " );
- Syntax.Append( "<I>" + ( (VisualBasicLangType)m_Parameters[i] ).ParamVarName + "</I>" );
-
- if ( ( (VisualBasicLangType)m_Parameters[i] ).IsRealArray )
- Syntax.Append( "()" );
-
- Syntax.Append( " As " + ( (VisualBasicLangType)m_Parameters[i] ).ClassName );
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- {
- if ( VarArgs )
- {
- Syntax.Append( ", -<BR/> ..." );
- }
- Syntax.Append( " _<BR/>" );
- }
- }
- Syntax.Append( ")" );
- if ( !m_ReturnLangType.ClassName.Equals( "Void" ) ){
- Syntax.Append( " As " );
- if ( m_ReturnLangType.m_IsByRef )
- Syntax.Append( "ByRef " );
- Syntax.Append( m_ReturnLangType.ClassName );
- if ( m_ReturnLangType.IsRealArray )
- Syntax.Append( "()" );
- }
- Syntax.Append( "</B></PRE>" );
- return Syntax.ToString();
- }
- }
-
- public override bool IsMethod()
- {
- return true;
- }
- }
-
- } // namespace LangUtil
-