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

  1. /*=====================================================================
  2.   File:      CSharpConstructorInfo.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 CSharpConstructorInfo : LangConstructorInfo
  29.    {
  30.       public CSharpConstructorInfo( ConstructorInfo myConstructor ): base( myConstructor )
  31.       {
  32.       }
  33.  
  34.       protected override ArrayList GetParamList( ParameterInfo[] ParamArray )
  35.       {
  36.          ArrayList ParamList = new ArrayList( ParamArray.Length );
  37.          for ( int x = 0; x < ParamArray.Length; x++ )
  38.          {
  39.             ParamList.Add( new CSharpLangType( ParamArray[x] ) );
  40.          }
  41.          return ParamList; 
  42.       }
  43.  
  44.       public Type ThisType
  45.       {
  46.          override get
  47.          { 
  48.             return m_ThisType;
  49.          }
  50.       }
  51.    
  52.       public String Attributes
  53.       {
  54.          override get 
  55.          {
  56.             StringBuilder sb = new StringBuilder();
  57.             
  58.             if ( m_ThisConstructorInfo.IsPublic )
  59.                sb.Append( "public " );
  60.             else if ( m_ThisConstructorInfo.IsPrivate )
  61.                sb.Append( "private " );
  62.             else if ( m_ThisConstructorInfo.IsFamily )
  63.                sb.Append( "protected " );
  64.             else if ( m_ThisConstructorInfo.IsAssembly )
  65.                sb.Append( "internal " );
  66.             else if ( m_ThisConstructorInfo.IsFamilyAndAssembly )
  67.                sb.Append( "FamilyAndAssembly " );
  68.             else if ( m_ThisConstructorInfo.IsFamilyOrAssembly )
  69.                sb.Append( "FamilyOrAssembly " );               
  70.  
  71.             // This information is implicit in interfaces....
  72.  
  73.             if ( !m_ThisConstructorInfo.DeclaringType.IsInterface )
  74.             {
  75.                if ( m_ThisConstructorInfo.IsAbstract )
  76.                   sb.Append( "abstract " );
  77.                if ( m_ThisConstructorInfo.IsVirtual && !m_ThisConstructorInfo.IsAbstract )
  78.                {
  79.                   ParameterInfo[] p = m_ThisConstructorInfo.GetParameters();
  80.                   Type[] param_types = new Type[p.Length];
  81.                   for ( int i = 0; i < param_types.Length; i++ )
  82.                   {
  83.                      param_types[i] = p[i].ParameterType;
  84.                   }
  85.  
  86.                   Type superClass = m_ThisConstructorInfo.ReflectedType.BaseType;
  87.  
  88.                   MethodInfo baseImpl = ( superClass == null ) ? null : 
  89.                                 superClass.GetMethod( m_ThisConstructorInfo.Name, param_types );
  90.  
  91.                   if ( baseImpl == null )
  92.                   {
  93.                      sb.Append( "virtual " );
  94.                   }
  95.                   else if ( m_ThisConstructorInfo.DeclaringType == m_ThisConstructorInfo.ReflectedType )
  96.                   {
  97.                      sb.Append( "override " );
  98.                   }
  99.                }
  100.             }
  101.             if ( m_ThisConstructorInfo.IsStatic )
  102.                sb.Append ( "static " );
  103.             return sb.ToString();
  104.          }
  105.        }
  106.  
  107.       public String ShortTextDeclaration 
  108.       {
  109.          get
  110.          {
  111.             StringBuilder Syntax = new StringBuilder( m_ThisConstructorInfo.ReflectedType.Name + "(" );
  112.             for ( int i = 0; i < m_Parameters.Count; i++ )
  113.             { 
  114.                Syntax.Append( ( (CSharpLangType)m_Parameters[i] ).ClassName );
  115.                if ( ( (CSharpLangType)m_Parameters[i] ).IsRealArray )
  116.                   Syntax.Append( "[]" );
  117.  
  118.                // writes the comma, or the last break.
  119.                if ( i != ( m_Parameters.Count - 1 ) )
  120.                   Syntax.Append( ", " );
  121.             } 
  122.             Syntax.Append( ")" );
  123.             return Syntax.ToString();
  124.          }
  125.       }
  126.  
  127.       public String TextDeclaration
  128.       {
  129.          override get
  130.          {
  131.             StringBuilder Syntax = new StringBuilder( Attributes + m_ThisConstructorInfo.ReflectedType.Name + "(" );
  132.             for ( int i = 0; i < m_Parameters.Count; i++ ) 
  133.             { 
  134.                if ( ((CSharpLangType)m_Parameters[i]).m_IsByRef )
  135.                   Syntax.Append( "ref " );
  136.                Syntax.Append( ((CSharpLangType)m_Parameters[i]).ClassName );
  137.                if ( ((CSharpLangType)m_Parameters[i]).IsRealArray )
  138.                   Syntax.Append( "[]" );
  139.  
  140.                Syntax.Append( " " + ((CSharpLangType)m_Parameters[i]).ParamVarName );
  141.  
  142.                // writes the comma, or the last break.
  143.                if ( i != ( m_Parameters.Count - 1 ) )
  144.                   Syntax.Append( ", " );
  145.             } 
  146.             Syntax.Append( ")" );
  147.             Syntax.Append( ";" );
  148.             return Syntax.ToString();
  149.          }
  150.       }
  151.  
  152.       public String HTMLDeclaration
  153.       {
  154.          override get
  155.          {
  156.             StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\">" );
  157.             Syntax.Append( "<span style=\"color:red\">[CSharp]</span><BR/>" );
  158.             
  159.             Syntax.Append( "<B>" );
  160.             Syntax.Append( Attributes + m_ThisConstructorInfo.ReflectedType.Name + "(" );
  161.             for ( int i = 0; i < m_Parameters.Count; i++ )
  162.             {                
  163.                Syntax.Append( "<BR/>    " );
  164.                if ( ( (CSharpLangType)m_Parameters[i] ).m_IsByRef )
  165.                   Syntax.Append( "ref " );
  166.                Syntax.Append( ( (CSharpLangType)m_Parameters[i] ).ClassName );
  167.                if ( ( (CSharpLangType)m_Parameters[i] ).IsRealArray )
  168.                   Syntax.Append( "[]" );
  169.  
  170.                Syntax.Append( " <I>" + ( (CSharpLangType)m_Parameters[i] ).ParamVarName + "</I>" );
  171.  
  172.                // Writes the comma, or the last break
  173.                if ( i != ( m_Parameters.Count - 1 ) )
  174.                   Syntax.Append( ", " );
  175.                else 
  176.                {
  177.                   Syntax.Append( "<BR/>" );
  178.                }
  179.             } 
  180.             Syntax.Append( ")" );
  181.             Syntax.Append( ";" );
  182.             Syntax.Append( "</B></PRE>" );
  183.          
  184.             return Syntax.ToString();
  185.          }
  186.       }
  187.  
  188.       public String Name
  189.       {
  190.          override get { return m_Name; }
  191.       }
  192.    }
  193.  
  194. } // namespace LangUtil
  195.