home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: LangConstructorInfo.cs
-
- Summary: LangConstructorInfo implements or declares all of the
- functionality that is required of subclasses that re-
- present constructors in a particular language.
-
- ---------------------------------------------------------------------
- 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 LangConstructorInfo : LangMember
- {
- // Internal data members that are loaded by the constructor.
- // These fields contain the information necessary for children to
- // build accurate language-translations
- protected String m_Name = String.Empty;
- protected ArrayList m_Parameters = null;
- protected ConstructorInfo m_ThisConstructorInfo = null;
- protected Type m_ThisType = null;
- protected bool m_Overloads = false;
-
- public LangConstructorInfo( 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.LookupAll );
- int cnt = 0;
- for ( int i = 0; i < allConstructors.Length; i++ )
- {
- if ( !allConstructors[i].IsPrivate && allConstructors[i].Name.Equals( m_Name ) )
- 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();
- 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;
- }
- }
-
- /*
- // GetParamList must be overridden by subclasses to return an ArrayList of
- // LangMembers that represent particular languages. As a result, callers merely
- // have to cast once to acquire the language-specific object.
- */
-
- protected virtual ArrayList GetParamList( ParameterInfo[] ParamArray )
- {
- throw new NotSupportedException( "GetParamList not yet implemented on this class." );
- }
-
- /* LangName can be overridden to provide a language-specific name for
- // the constructor. For example, the Visual Basic constructor name
- // is "New" rather than the name of the class or .ctor.
- */
-
- // Note: Recall that Types may return []*& appended if this is called on a parameter
- // or return type.
-
- public String LangName
- {
- virtual get
- {
- return m_ThisConstructorInfo.ReflectedType.Name;
- }
- }
-
- public String Name
- {
- override get { return m_Name; }
- }
-
- public ConstructorInfo ThisConstructorInfo
- {
- get { return m_ThisConstructorInfo; }
- }
-
- public override bool IsConstructor()
- {
- return true;
- }
- }
-
- } // namespace LangUtil
-