Analyze method parameters using reflection : Parameter « Reflection « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Reflection » Parameter 
19.6.3.Analyze method parameters using reflection
using System; 
using System.Reflection; 
 
class MyClass 
  public MyClass(int i, int j) { 
  
 
  public int sum() { 
    return 0
  
 
  public bool isBetween(int i) { 
    return false
  
 
  public void set(int a, int b) { 
  
 
  public void set(double a, double b) { 
  
 
  public void show() { 
    Console.WriteLine("show")
  

 
class MainClass 
  public static void Main() { 
    Type t = typeof(MyClass);
 
    Console.WriteLine("Analyzing methods in " + t.Name);     
    Console.WriteLine()
 
    Console.WriteLine("Methods supported: ")
 
    MethodInfo[] mi = t.GetMethods()
 
    // Display methods supported by MyClass. 
    foreach(MethodInfo m in mi) { 
      // Display return type and name. 
      Console.Write("   " + m.ReturnType.Name + 
                      " " + m.Name + "(")
 
      // Display parameters. 
      ParameterInfo[] pi = m.GetParameters()
 
      for(int i=0; i < pi.Length; i++) { 
        Console.Write(pi[i].ParameterType.Name + 
                      " " + pi[i].Name)
        if(i+< pi.LengthConsole.Write(", ")
      
 
      Console.WriteLine(")")
     
      Console.WriteLine()
    
  
}
Analyzing methods in MyClass

Methods supported:
   Int32 sum()

   Boolean isBetween(Int32 i)

   Void set(Int32 a, Int32 b)

   Void set(Double a, Double b)

   Void show()

   Type GetType()

   String ToString()

   Boolean Equals(Object obj)

   Int32 GetHashCode()
19.6.Parameter
19.6.1.Invoke method with parameter type int
19.6.2.Generic parameter information
19.6.3.Analyze method parameters using reflection
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.