home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: VisualBasicConstructorInfo.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 VisualBasicConstructorInfo : LangMember
- {
- internal String m_Name = String.Empty;
- internal ArrayList m_Parameters = new ArrayList();
- internal ConstructorInfo m_ThisConstructorInfo = null;
- internal Type m_ThisType = null;
- internal bool m_Overloads = false;
-
- public VisualBasicConstructorInfo( ConstructorInfo myConstructor )
- {
- if ( myConstructor == null )
- throw new NullReferenceException( "The ConstructorInfo passed to the constructor is null." );
-
- m_ThisConstructorInfo = myConstructor;
- m_Name = myConstructor.Name;
- m_ThisType = myConstructor.ReflectedType;
-
- // Initialize "m_Overloads" to true if there is more than 1 non-private constructor
- ConstructorInfo[] allConstructors = myConstructor.DeclaringType.GetConstructors( BindingFlags.NonPublic );
- int cnt = 0;
- for ( int i = 0; i < allConstructors.Length; i++ )
- {
- if ( !allConstructors[i].IsPrivate )
- cnt++;
- }
- if ( cnt > 1 )
- m_Overloads = true;
-
- // Determine whether method can accept variable-length arguments
- if ( myConstructor.CallingConvention == CallingConventions.VarArgs )
- m_VarArgs = true;
-
- // Obtain list of indexed properties
- ParameterInfo[] myParams = myConstructor.GetParameters();
-
- for ( int x = 0; x < myParams.Length; x++ )
- {
- m_Parameters.Add( new VisualBasicLangType( myParams[x] ) );
- }
- }
-
- public Type ThisType
- {
- override get { return m_ThisType; }
- }
-
- public String Attributes
- {
- override get
- {
- StringBuilder sb = new StringBuilder();
- if ( m_ThisConstructorInfo.IsAbstract )
- sb.Append( "MustOverride " );
-
- if ( m_ThisConstructorInfo.IsFinal && !m_ThisConstructorInfo.DeclaringType.IsSealed && !m_ThisConstructorInfo.DeclaringType.IsInterface )
- sb.Append( "CantOverride " );
-
- if ( m_Overloads )
- sb.Append( "Overloads " );
-
- if ( m_ThisConstructorInfo.IsPublic )
- sb.Append( "Public " );
- else if ( m_ThisConstructorInfo.IsPrivate )
- sb.Append( "Private " );
- else if ( m_ThisConstructorInfo.IsFamily )
- sb.Append( "Protected " );
- else if ( m_ThisConstructorInfo.IsAssembly )
- sb.Append( "Assembly " );
- else if ( m_ThisConstructorInfo.IsFamilyAndAssembly )
- sb.Append( "FamilyAndAssembly " );
- else if ( m_ThisConstructorInfo.IsFamilyOrAssembly )
- sb.Append( "FamilyOrAssembly " );
-
- if ( m_ThisConstructorInfo.IsStatic )
- sb.Append( "Shared " );
-
- sb.Append( "Sub " );
-
- return sb.ToString();
- }
- }
-
- public String ShortTextDeclaration
- {
- get
- {
- StringBuilder Syntax = new StringBuilder( m_ThisConstructorInfo.ReflectedType.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( String.Empty );
- if ( Attributes.IndexOf( "Overloads" ) == -1 )
- Syntax.Append( "Overloads " );
- Syntax.Append( Attributes );
- Syntax.Append( "New" );
- 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 " );
- Syntax.Append( ( (VisualBasicLangType)m_Parameters[i] ).ParamVarName );
- 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
- {
- }
- }
- Syntax.Append( ")" );
- return Syntax.ToString();
- }
- }
-
- public String HTMLDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\"><B>" );
-
- if ( Attributes.IndexOf( "Overloads" ) == -1 )
- Syntax.Append( "Overloads " );
- Syntax.Append( Attributes );
- Syntax.Append( "New(" );
-
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- Syntax.Append( " _" );
-
- Syntax.Append( "<BR> " );
- if ( ( (VisualBasicLangType)m_Parameters[i] ).m_IsByRef )
- Syntax.Append( "ByRef " );
- else
- Syntax.Append( "ByVal " );
- Syntax.Append( "<I>" + ( (VisualBasicLangType)m_Parameters[i] ).ParamVarName );
- if ( ((VisualBasicLangType)m_Parameters[i] ).IsRealArray )
- Syntax.Append( "()" );
- Syntax.Append( "</I> As " + ( (VisualBasicLangType)m_Parameters[i] ).ClassName );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- {
- Syntax.Append( " _<BR>" );
- }
- }
- Syntax.Append( ")</B></PRE>" );
- return Syntax.ToString();
- }
- }
-
- public String LangName
- {
- get { return "New"; }
- }
-
- public ArrayList Parameters
- {
- get { return m_Parameters;}
- }
-
- public String Name
- {
- override get { return m_Name; }
- }
-
- public ConstructorInfo ThisConstructorInfo
- {
- get { return m_ThisConstructorInfo; }
- }
-
- public bool Overloads
- {
- get { return m_Overloads; }
- }
-
- public override bool IsConstructor()
- {
- return true;
- }
- }
-
- } // namespace LangUtil
-