home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: MCConstructorInfo.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 MCConstructorInfo : 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 MCConstructorInfo( 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 MCLangType( myParams[x] ) );
- }
- }
-
- public Type ThisType
- {
- override get { return m_ThisType; }
- }
-
- public String Attributes
- {
- override get
- {
- StringBuilder sb = new StringBuilder();
-
- // Append access modifier
- if ( m_ThisConstructorInfo.IsPublic )
- sb.Append( "public: " );
- else if ( m_ThisConstructorInfo.IsPrivate )
- sb.Append( "private: " );
- else if ( m_ThisConstructorInfo.IsFamily )
- sb.Append( "protected: " );
- // What the correct keywords for these???:
- else if ( m_ThisConstructorInfo.IsAssembly )
- sb.Append( "Assembly: " );
- else if ( m_ThisConstructorInfo.IsFamilyAndAssembly )
- sb.Append( "FamilyAndAssembly: " );
- else if ( m_ThisConstructorInfo.IsFamilyOrAssembly )
- sb.Append( "FamilyOrAssembly: " );
-
- 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( ( (MCLangType)m_Parameters[i] ).ClassName );
- if ( ( (MCLangType)m_Parameters[i] ).m_IsArray )
- Syntax.Append( "[]" );
- if ( ( (MCLangType)m_Parameters[i] ).IsByRef )
- Syntax.Append( "*" );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- }
- Syntax.Append( ")" );
- return Syntax.ToString();
- }
- }
-
- public String TextDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( this.Attributes + m_ThisConstructorInfo.ReflectedType.Name + "(" );
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- Syntax.Append( ( (MCLangType)m_Parameters[i] ).ClassName );
- if ( ( (MCLangType)m_Parameters[i] ).m_IsArray )
- Syntax.Append( "[]" );
- if ( ( (MCLangType)m_Parameters[i] ).m_IsByRef )
- Syntax.Append( "*" );
- if ( ( (MCLangType)m_Parameters[i] ).m_IsPointer )
- Syntax.Append( "*" );
- Syntax.Append( " " + ((MCLangType)m_Parameters[i]).ParamVarName );
-
- // Writes the comma, or the last break
- if ( i != ( m_Parameters.Count - 1 ) )
- 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\">[MC++]</span><BR>" );
-
- Syntax.Append( "<B>" );
- Syntax.Append( this.Attributes + m_ThisConstructorInfo.ReflectedType.Name + "(" );
- for ( int i = 0; i < m_Parameters.Count; i++ )
- {
- Syntax.Append( "<BR> " );
- Syntax.Append( ( (MCLangType)m_Parameters[i] ).ClassName );
- if ( ( (MCLangType)m_Parameters[i] ).m_IsArray )
- Syntax.Append( "[]" );
- if ( ( (MCLangType)m_Parameters[i] ).m_IsByRef )
- Syntax.Append( "*" );
- Syntax.Append( " <I>" + ( (MCLangType)m_Parameters[i] ).ParamVarName + "</I>" );
-
- // Writes the comma, or the last break
- if ( i != (m_Parameters.Count - 1 ) )
- Syntax.Append( ", " );
- else
- Syntax.Append( "<BR>" );
- }
- Syntax.Append( ")" );
- Syntax.Append( ";" );
- Syntax.Append( "</B></PRE>" );
-
- return Syntax.ToString();
- }
- }
-
- public String LangName
- {
- get { return m_ThisConstructorInfo.ReflectedType.Name; }
- }
-
- 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
-