home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: LangPropertyInfo.cs
-
- Summary: Implements or declares all the functionality common to
- subclasses of this class.
-
- ---------------------------------------------------------------------
- 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 abstract class LangPropertyInfo : LangMember
- {
- protected String m_Name = String.Empty;
- protected PropertyInfo m_ThisPropertyInfo = null;
-
- // Must implement these on the children
- protected CSharpLangType m_GetSetType = null;
- protected CSharpMethodInfo m_Getter = null;
- protected CSharpMethodInfo m_Setter = null;
-
- protected ArrayList m_Parameters = new ArrayList();
- protected String m_Access = String.Empty;
-
- public LangPropertyInfo( PropertyInfo myProperty )
- {
- try
- {
- if ( myProperty == null )
- throw new NullReferenceException( "The PropertyInfo passed to the constructor is null." );
-
- // Obtain Property Name and Type
- m_Name = myProperty.Name;
- m_ThisPropertyInfo = myProperty;
-
- // Obtain Getter and Setter
- if ( myProperty.CanRead )
- {
- m_Getter = new CSharpMethodInfo( myProperty.GetGetMethod( true ) );
- }
- if ( myProperty.CanWrite )
- {
- m_Setter = new CSharpMethodInfo( myProperty.GetSetMethod( true ) );
- }
-
-
- CSharpMethodInfo obj;
-
- if ( myProperty.CanRead )
- {
- ParameterInfo[] tmpArray = myProperty.GetGetMethod( true ).GetParameters();
-
- // SEE Member.aspx, THE LAST ARG IS RETURN TYPE OF GETTER
- for ( int i = 0; i < tmpArray.Length; i++ )
- {
- m_Parameters.Add( new CSharpLangType( tmpArray[i] ) );
- }
-
- m_GetSetType = new CSharpLangType( myProperty.GetGetMethod( true ).ReturnType );
- obj = m_Getter;
- }
- else if ( myProperty.CanWrite )
- {
- ParameterInfo[] tmpArray = myProperty.GetSetMethod( true ).GetParameters();
-
- // SEE Member.aspx, THE LAST ARG IS NOT AN ARG OF GETTER
- for ( int i = 0; i < tmpArray.Length - 1; i++ )
- {
- m_Parameters.Add( new CSharpLangType( tmpArray[i] ) );
- }
-
- // THE LAST ARG HAS SAME TYPE AS THE TYPE OF THIS PROPERTY
- m_GetSetType = new CSharpLangType( tmpArray[tmpArray.Length - 1] );
- obj = m_Setter;
- }
- else
- {
- ;
- }
-
- }
- catch ( Exception Ex )
- {
- throw new Exception( Ex.GetType().Name + " error in property constructor.", Ex );
- }
- }
-
- public ArrayList Parameters
- {
- get { return m_Parameters; }
- }
-
- public String Name
- {
- override get { return m_Name; }
- }
-
- /*
- // This property must be implemented on subclasses to return a LangType for that
- // language that the current class represents to avoid callers having to
- public <LanguageName>LangType GetSetLangType{
- get{
- return m_GetSetType;
- }
- }
- */
-
- public Type ThisType
- {
- override get { return m_ThisPropertyInfo.ReflectedType; }
- }
-
- public String TextDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( Access );
- Syntax.Append( m_GetSetType.ClassName + " " );
- if ( m_Name.Equals( "Item" ) )
- Syntax.Append( "this" );
- else
- Syntax.Append( m_Name );
- if ( m_Parameters.Count > 0 )
- Syntax.Append( "[" );
- for ( int j = 0; j < m_Parameters.Count; j++ )
- {
- Syntax.Append( ( (CSharpLangType)m_Parameters[j] ).ClassName );
- Syntax.Append( " " + ( (CSharpLangType)m_Parameters[j] ).ParamVarName );
- if ( j != ( m_Parameters.Count - 1 ) )
- {
- Syntax.Append( ", " );
- }
- else
- {
- Syntax.Append( "]" );
- }
- }
- Syntax.Append( " {" );
- if ( m_ThisPropertyInfo.CanRead )
- {
- if ( m_Getter.Attributes.IndexOf( "override" ) > -1 )
- Syntax.Append( "override " );
- else if ( m_Getter.Attributes.IndexOf( "abstract" ) > -1 )
- Syntax.Append( "abstract " );
- else if ( m_Getter.Attributes.IndexOf( "virtual" ) > -1 )
- Syntax.Append( "virtual " );
- Syntax.Append( "get;" );
- }
- if ( m_ThisPropertyInfo.CanWrite )
- {
- if ( m_Setter.Attributes.IndexOf( "override" ) > -1 )
- Syntax.Append( "override " );
- else if ( m_Setter.Attributes.IndexOf( "abstract" ) > -1 )
- Syntax.Append( "abstract " );
- else if ( m_Setter.Attributes.IndexOf( "virtual" ) > -1 )
- Syntax.Append( "virtual " );
- Syntax.Append( "set;" );
- }
- Syntax.Append( "}" );
- return Syntax.ToString();
- }
- }
-
- public string HTMLDeclaration
- {
- override get
- {
- StringBuilder Syntax = new StringBuilder( "<PRE class=\"Syntax\">" );
- Syntax.Append( "<span style=\"color:red\">[CSharp]</span><BR/><B>" );
- Syntax.Append( Access );
-
- Syntax.Append( m_GetSetType.ClassName + " " );
- if ( m_Name.Equals( "Item" ) )
- Syntax.Append( "this" );
- else
- Syntax.Append( m_Name );
- if ( m_Parameters.Count > 0 )
- Syntax.Append( "[" );
- for ( int j = 0; j < m_Parameters.Count; j++ )
- {
- Syntax.Append( ( (CSharpLangType)m_Parameters[j] ).ClassName );
- // write the variable name.
- Syntax.Append( " <I>" + ( (CSharpLangType)m_Parameters[j] ).ParamVarName + "</I>" );
- if ( j != ( m_Parameters.Count - 1 ) )
- {
- Syntax.Append( ", " );
- }
- else
- {
- Syntax.Append( "]" );
- }
- }
- Syntax.Append( " {<BR/> " );
- if ( m_ThisPropertyInfo.CanRead )
- {
- if ( m_Getter.Attributes.IndexOf( "override" ) > -1 )
- Syntax.Append( "override " );
- else if ( m_Getter.Attributes.IndexOf( "abstract" ) > -1 )
- Syntax.Append( "abstract " );
- else if ( m_Getter.Attributes.IndexOf( "virtual" ) > -1 )
- Syntax.Append( "virtual " );
- Syntax.Append( "get;" );
- }
- if ( m_ThisPropertyInfo.CanWrite )
- {
- Syntax.Append( "<BR/> " );
- if ( m_Setter.Attributes.IndexOf( "override" ) > -1 )
- Syntax.Append( "override " );
- else if ( m_Setter.Attributes.IndexOf( "abstract" ) > -1 )
- Syntax.Append( "abstract " );
- else if (m_Setter.Attributes.IndexOf( "virtual" ) > -1 )
- Syntax.Append( "virtual " );
- Syntax.Append( "set;" );
- }
- Syntax.Append( "<BR/>}</B></PRE>" );
- return Syntax.ToString();
- }
- }
-
- // Access must be implemented by children. It returns a string containing the
- // level of access exposed by the accessor methods for this property
- // IFF the two levels are the same. If they are not, it throws an exception.
-
- protected String Access
- {
- abstract get;
- }
-
- public String Attributes
- {
- override get { return this.Access; }
- }
-
- public override bool IsProperty()
- {
- return true;
- }
- }
-
- } // namespace LangUtil
-