home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: Util.cs
-
- Summary: Brief summary of the file contents and purpose.
-
- ---------------------------------------------------------------------
- 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;
-
- public class Util
- {
- /*************************************************
-
- GetHKey the method that generates the
- id element that I use as the hash key.
-
- **************************************************/
-
- public static String GetHKey( MemberInfo mmm )
- {
- String ID = String.Empty;
- // Methods and Constructors
- if ( mmm is MethodBase )
- {
- // So that the hash is created properly between constructors,
- // whose name is now .ctor.
- if ( mmm is ConstructorInfo )
- ID = mmm.DeclaringType.Name + " (";
- else
- ID = mmm.Name + " (";
- ParameterInfo[] ps = ((MethodBase)mmm ).GetParameters();
- for ( int j = 0; j < ps.Length; j++ )
- {
- ID = ID + ps[j].ParameterType.Name;
- if ( j < ps.Length - 1 )
- ID = ID + ", ";
- }
- ID = ID + ")";
- // Append return type for methods
- if ( mmm is MethodInfo )
- ID = ID + " " + ( (MethodInfo )mmm ).ReturnType.Name;
- }
-
- // Properties
- else if ( mmm is PropertyInfo )
- {
- ID = mmm.Name;
- ParameterInfo[] ps = ( (PropertyInfo)mmm ).GetIndexParameters();
- if ( ps.Length > 0 )
- {
- ID = ID + " [";
- for ( int j = 0; j < ps.Length; j++ )
- {
- ID = ID + ps[j].ParameterType.Name;
- if ( j < ps.Length - 1)
- ID = ID + ", ";
- }
- ID = ID + "]";
- }
- // append "return" type. Note: GetType() is NYI on PropertyInfo
- // NEED TO FIX THIS, but perhaps we don't have any write-only properties
- if ( ( (PropertyInfo)mmm).CanRead )
- ID = ID + " " + ( (PropertyInfo)mmm).GetGetMethod( true ).ReturnType.Name;
- else
- ID = ID + " " + "WriteOnly"; // I don't know the correct semantics/syntax for properties
- }
- // Fields
- else if ( mmm is FieldInfo )
- ID = mmm.Name + " " + ( (FieldInfo)mmm ).FieldType.Name;
-
- // Events
- else if ( mmm is EventInfo )
- {
- // ID = "Event " + mmm.Name + " " + ( (EventInfo)mmm ).EventHandler.Name;
- }
-
- else
- {
- Console.WriteLine( "UNABLE TO CREATE HASH ID FOR: " + mmm.Name );
- return "ERROR";
- }
- return ID;
- }
- }
-
- } // namespace LangUtil
-