home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / ClsView / VisualBasicConstructorInfo.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  8.0 KB  |  237 lines

  1. /*=====================================================================
  2.   File:      VisualBasicConstructorInfo.cs
  3.  
  4.   Summary:   Brief summary of the file contents and purpose.
  5.  
  6. ---------------------------------------------------------------------
  7.   This file is part of the Microsoft NGWS SDK Code Samples.
  8.  
  9.   Copyright (C) 2000 Microsoft Corporation.  All rights reserved.
  10.  
  11. This source code is intended only as a supplement to Microsoft
  12. Development Tools and/or on-line documentation.  See these other
  13. materials for detailed information regarding Microsoft code samples.
  14.  
  15. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  16. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  18. PARTICULAR PURPOSE.
  19. =====================================================================*/
  20.  
  21. namespace LangUtil {
  22.  
  23. using System;
  24. using System.Text;
  25. using System.Reflection;
  26. using System.Collections;
  27.  
  28.    public class VisualBasicConstructorInfo : LangMember
  29.    {
  30.       internal String m_Name = String.Empty;
  31.       internal ArrayList m_Parameters = new ArrayList();
  32.       internal ConstructorInfo m_ThisConstructorInfo =  null;
  33.       internal Type m_ThisType = null;
  34.       internal bool m_Overloads = false;      
  35.  
  36.       public VisualBasicConstructorInfo( ConstructorInfo myConstructor )
  37.       {
  38.          if ( myConstructor == null )
  39.             throw new NullReferenceException( "The ConstructorInfo passed to the constructor is null." );
  40.  
  41.          m_ThisConstructorInfo = myConstructor;
  42.          m_Name = myConstructor.Name;
  43.          m_ThisType = myConstructor.ReflectedType;
  44.  
  45.          // Initialize "m_Overloads" to true if there is more than 1 non-private constructor
  46.          ConstructorInfo[] allConstructors = myConstructor.DeclaringType.GetConstructors( BindingFlags.NonPublic );
  47.          int cnt = 0;
  48.          for ( int i = 0; i < allConstructors.Length; i++ )
  49.          {
  50.             if ( !allConstructors[i].IsPrivate )
  51.                cnt++;
  52.          }
  53.          if ( cnt > 1 )
  54.             m_Overloads = true;
  55.  
  56.          // Determine whether method can accept variable-length arguments
  57.          if ( myConstructor.CallingConvention == CallingConventions.VarArgs )
  58.             m_VarArgs = true;
  59.       
  60.          // Obtain list of indexed properties          
  61.          ParameterInfo[] myParams = myConstructor.GetParameters();
  62.  
  63.          for ( int x = 0; x < myParams.Length; x++ )
  64.          {
  65.             m_Parameters.Add( new VisualBasicLangType( myParams[x] ) );
  66.          }
  67.       }
  68.  
  69.       public Type ThisType
  70.       {
  71.          override get { return m_ThisType; }
  72.       }
  73.    
  74.       public String Attributes
  75.       {
  76.          override get 
  77.          { 
  78.             StringBuilder sb = new StringBuilder();        
  79.             if ( m_ThisConstructorInfo.IsAbstract )
  80.                sb.Append( "MustOverride " );
  81.                
  82.             if ( m_ThisConstructorInfo.IsFinal && !m_ThisConstructorInfo.DeclaringType.IsSealed && !m_ThisConstructorInfo.DeclaringType.IsInterface )
  83.                sb.Append( "CantOverride " );
  84.  
  85.             if ( m_Overloads )
  86.                sb.Append( "Overloads " );
  87.  
  88.             if ( m_ThisConstructorInfo.IsPublic )
  89.                sb.Append( "Public " );
  90.             else if ( m_ThisConstructorInfo.IsPrivate )
  91.                sb.Append( "Private " );
  92.             else if ( m_ThisConstructorInfo.IsFamily )
  93.                sb.Append( "Protected " );
  94.             else if ( m_ThisConstructorInfo.IsAssembly )
  95.                sb.Append( "Assembly " );
  96.             else if ( m_ThisConstructorInfo.IsFamilyAndAssembly )
  97.                sb.Append( "FamilyAndAssembly " );
  98.             else if ( m_ThisConstructorInfo.IsFamilyOrAssembly )
  99.                sb.Append( "FamilyOrAssembly " );
  100.  
  101.             if ( m_ThisConstructorInfo.IsStatic )
  102.                sb.Append( "Shared " );
  103.             
  104.             sb.Append( "Sub " );
  105.                
  106.             return sb.ToString();
  107.          }
  108.       }
  109.  
  110.       public String ShortTextDeclaration
  111.       {
  112.          get
  113.          {
  114.             StringBuilder Syntax = new StringBuilder( m_ThisConstructorInfo.ReflectedType.Name + "(" );
  115.             for ( int i = 0; i < m_Parameters.Count; i++ )
  116.             { 
  117.                Syntax.Append( ( (VisualBasicLangType)m_Parameters[i]).ClassName );
  118.                if ( ( (VisualBasicLangType)m_Parameters[i] ).IsRealArray )
  119.                   Syntax.Append( "()" );
  120.                
  121.                // Writes the comma, or the last break
  122.                if ( i != ( m_Parameters.Count - 1 ) )
  123.                   Syntax.Append( ", " );
  124.                else
  125.                {
  126.                }
  127.             }
  128.             Syntax.Append( ")" );
  129.             return Syntax.ToString();
  130.          }
  131.       }
  132.  
  133.       public String TextDeclaration
  134.       {
  135.          override get
  136.          {
  137.             StringBuilder Syntax = new StringBuilder( String.Empty );
  138.             if ( Attributes.IndexOf( "Overloads" ) == -1 )
  139.                Syntax.Append( "Overloads " );
  140.             Syntax.Append( Attributes );
  141.             Syntax.Append( "New" );
  142.             Syntax.Append( "(" );
  143.             for ( int i = 0; i < m_Parameters.Count; i++ ) 
  144.             { 
  145.                if ( ( (VisualBasicLangType)m_Parameters[i] ).m_IsByRef )
  146.                   Syntax.Append( "ByRef " );
  147.                else
  148.                   Syntax.Append( "ByVal " );
  149.                Syntax.Append( ( (VisualBasicLangType)m_Parameters[i] ).ParamVarName );
  150.                if ( ( (VisualBasicLangType)m_Parameters[i] ).IsRealArray )
  151.                   Syntax.Append( "()" );
  152.  
  153.                Syntax.Append( " As " + ( (VisualBasicLangType)m_Parameters[i] ).ClassName );
  154.  
  155.                // Writes the comma, or the last break
  156.                if ( i != (m_Parameters.Count - 1 ) )
  157.                   Syntax.Append( ", " );
  158.                else
  159.                {
  160.                }
  161.             }
  162.             Syntax.Append( ")" );
  163.             return Syntax.ToString();
  164.          }
  165.       }
  166.  
  167.       public String HTMLDeclaration
  168.       {
  169.          override get
  170.          {
  171.             StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\"><B>" );
  172.             
  173.             if ( Attributes.IndexOf( "Overloads" ) == -1 )
  174.                Syntax.Append( "Overloads " );
  175.             Syntax.Append( Attributes );
  176.             Syntax.Append( "New(" );
  177.  
  178.             for ( int i = 0; i < m_Parameters.Count; i++ )
  179.             {
  180.                Syntax.Append( " _" );
  181.                
  182.                Syntax.Append( "<BR>    " );
  183.                if ( ( (VisualBasicLangType)m_Parameters[i] ).m_IsByRef )
  184.                   Syntax.Append( "ByRef " );
  185.                else
  186.                   Syntax.Append( "ByVal " );
  187.                Syntax.Append( "<I>" + ( (VisualBasicLangType)m_Parameters[i] ).ParamVarName );
  188.                if ( ((VisualBasicLangType)m_Parameters[i] ).IsRealArray )
  189.                   Syntax.Append( "()" );
  190.                Syntax.Append( "</I> As " + ( (VisualBasicLangType)m_Parameters[i] ).ClassName );
  191.  
  192.                // Writes the comma, or the last break
  193.                if ( i != ( m_Parameters.Count - 1 ) )
  194.                   Syntax.Append( ", " );
  195.                else 
  196.                {
  197.                   Syntax.Append( " _<BR>" );
  198.                }
  199.             } 
  200.             Syntax.Append( ")</B></PRE>" );
  201.             return Syntax.ToString();
  202.          }
  203.       }
  204.  
  205.       public String LangName
  206.       {
  207.          get { return "New"; }
  208.       }
  209.  
  210.       public ArrayList Parameters
  211.       {
  212.          get { return m_Parameters;}      
  213.       }
  214.  
  215.       public String Name
  216.       {
  217.          override get { return m_Name; }
  218.       }
  219.       
  220.       public ConstructorInfo ThisConstructorInfo
  221.       {
  222.          get { return m_ThisConstructorInfo; }
  223.       }      
  224.  
  225.       public bool Overloads
  226.       {
  227.          get { return m_Overloads; }
  228.       }
  229.  
  230.       public override bool IsConstructor()
  231.       {
  232.          return true;
  233.       }
  234.    }
  235.  
  236. } // namespace LangUtil
  237.