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

  1. /*=====================================================================
  2.   File:      CSharpFieldInfo.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 CSharpFieldInfo : LangFieldInfo
  29.    {
  30.       public CSharpFieldInfo( FieldInfo myField ) : base( myField )
  31.       {
  32.       }
  33.  
  34.       public string FieldLangTypeName
  35.       {
  36.          override get
  37.          { 
  38.             return new CSharpLangType( m_ThisFieldInfo.FieldType ).ClassName; 
  39.          }
  40.       }
  41.  
  42.       public CSharpLangType FieldLangType
  43.       {
  44.          get { return new CSharpLangType( m_ThisFieldInfo.FieldType ); } 
  45.       }
  46.  
  47.       public Type ThisType
  48.       {
  49.          override get { return m_ThisFieldInfo.ReflectedType; }
  50.       }
  51.  
  52.       public override bool IsField() { return true; }
  53.  
  54.       public String Name 
  55.       { 
  56.          override get{ return m_Name; }
  57.       }
  58.  
  59.       public string TextDeclaration
  60.       {
  61.          override get
  62.          {
  63.             StringBuilder Syntax = new StringBuilder( Attributes + FieldLangTypeName );
  64.             Syntax.Append( " " );
  65.             Syntax.Append( m_Name );
  66.             string temp = GetValueOfField();
  67.             if ( !temp.Equals( String.Empty ) )
  68.             {
  69.                Syntax.Append( " = " + temp );
  70.             }
  71.             Syntax.Append( ";" );
  72.             return Syntax.ToString();
  73.          }
  74.       }
  75.  
  76.       public string HTMLDeclaration
  77.       {
  78.          override get
  79.          {
  80.             StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\">" );
  81.             Syntax.Append( "<span style=\"color:red\">[CSharp]</span><BR/><B>" );
  82.             Syntax.Append( Attributes );
  83.             Syntax.Append( FieldLangTypeName );
  84.             Syntax.Append( " " );
  85.             Syntax.Append( m_Name );
  86.  
  87.             string temp = GetValueOfField();
  88.             if ( !temp.Equals( String.Empty ) )
  89.             {
  90.                Syntax.Append( " = " + temp );
  91.             }
  92.             Syntax.Append( ";" );
  93.             Syntax.Append( "</B></PRE>" );
  94.             return Syntax.ToString();
  95.          }
  96.       }
  97.  
  98.       /*
  99.       <Syntax lang="MS Managed C++" ver="7.0">
  100.       MustOverride Overloads Public Function GetEnumerator( _
  101.       ByVal allowRemove As <XRef type="ValueType" name="System.Boolean">Boolean</Xref> _
  102.       ) As <XRef type="Interface" name="System.Collections.IEnumerator">IEnumerator</XRef>
  103.       </Syntax> 
  104.       */
  105.  
  106.       public string XMLDeclaration
  107.       {
  108.          override get
  109.          {
  110.             StringBuilder Syntax = new StringBuilder( "<Syntax lang=\"MS CSharp\" ver=\"7.0\"><Txt>" );
  111.             Syntax.Append( Attributes );
  112.             Syntax.Append( "</Txt>" + MakeXRef( FieldLangType.ThisType, FieldLangTypeName ) );
  113.             Syntax.Append( "<Txt> " );
  114.             Syntax.Append( m_Name );
  115.  
  116.             string temp = GetValueOfField();
  117.             if ( !temp.Equals( String.Empty ) )
  118.             {
  119.                Syntax.Append( " = " + temp );
  120.             }
  121.             Syntax.Append( ";" );
  122.             Syntax.Append( "</Txt></Syntax>" );
  123.             return Syntax.ToString();
  124.          }
  125.       }
  126.  
  127.       public String Attributes
  128.       {
  129.          override get
  130.          {
  131.             StringBuilder sb = new StringBuilder();
  132.             
  133.             // APPEND ACCESS MODIFIER
  134.             if ( m_ThisFieldInfo.IsPublic )
  135.                sb.Append( "public " );
  136.             else if ( m_ThisFieldInfo.IsPrivate )
  137.                sb.Append( "private " );
  138.             else if ( m_ThisFieldInfo.IsFamily )
  139.                sb.Append( "protected " );
  140.             else if ( m_ThisFieldInfo.IsAssembly )
  141.                sb.Append( "internal " );
  142.             else if ( m_ThisFieldInfo.IsFamilyAndAssembly )
  143.                sb.Append( "FamilyAndAssembly " );
  144.             else if ( m_ThisFieldInfo.IsFamilyOrAssembly )
  145.                sb.Append( "FamilyOrAssembly " );            
  146.             
  147.             if ( m_ThisFieldInfo.IsLiteral && m_ThisFieldInfo.IsStatic )
  148.                sb.Append( "const " );
  149.             // If both Literal and InitOnly and true then const and InitOnly are written
  150.  
  151.             if ( m_ThisFieldInfo.IsInitOnly )
  152.                sb.Append( "readonly " );
  153.             if ( m_ThisFieldInfo.IsStatic && !m_ThisFieldInfo.IsLiteral )
  154.                sb.Append( "static " );
  155.             
  156.             return sb.ToString();
  157.          }
  158.        }
  159.  
  160.    } // End class
  161.  
  162. } // namespace LangUtil
  163.  
  164.