Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seeking sample code: (1) enumerating windows (2) reflection

Status
Not open for further replies.

Technobabe

Technical User
Feb 12, 2003
2
0
0
US
Hello,

Having read up on both of the topics below, I'd next like "real-world" examples to review:

(1) using Win32 API to enumerate windows

(2) using a console (or WinForms-based) to display

- The name of all public classes
- the names and parameters of all public methods (for each public class)

(for a module that you input)

Thanks in advance to anyone/everyone who pitches in cool code to look at!

TB
 
Hi,

Here is some sample code for Reflection:
Code:
/**
* File: ReflectTypes.cs
* Article: C# Reflection and Dynamic Method Invocation
* Copyright (c) 2000, Gopalan Suresh Raj. All Rights Reserved.
* Compile with: csc ReflectTypes
* Run as: ReflectTypes <library>
*         eg., ReflectTypes ImplementationOne.dll
*/

using System;
using System.Reflection;

/**
* Develop a class that can Reflect all the Types available in an Assembly
*/
class ReflectTypes {

public static void Main (string[] args) {

  // List all the types in the assembly that is passed in as a parameter
  Assembly assembly = Assembly.LoadFrom (args[0]);

  // Get all Types available in the assembly in an array
  Type[] typeArray = assembly.GetTypes ();

  Console.WriteLine ("The Different Types of Classes Available in {0} are:", args[0]);
  Console.WriteLine ("_____");
  // Walk through each Type and list their Information
  foreach (Type type in typeArray) {
   // Print the Class Name
   Console.WriteLine ("Type Name : {0}", type.FullName);
   // Print the name space
   Console.WriteLine ("Type Namespace : {0}", type.Namespace);
   // Print the Base Class Name
   Console.WriteLine ("Type Base Class : {0}", (type.BaseType != null)?type.BaseType.FullName:"No Base Class Found...");
   Console.WriteLine ("_____");
  }
}
}

There are lots and lots of examples more to be found on google.

- Raenius

&quot;Free will...is an illusion&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top