Get parameter information by using ConstructorInfo and ParameterInfo : ConstructorInfo « Reflection « C# / C Sharp






Get parameter information by using ConstructorInfo and ParameterInfo

    

using System;
using System.Collections;
using System.Reflection;

public class MainClass{
    public static void Main() {
        Assembly LoadedAsm = Assembly.LoadFrom("yourName");
        Console.WriteLine(LoadedAsm.FullName);
        Type[] LoadedTypes = LoadedAsm.GetTypes();
        if (LoadedTypes.Length == 0) {
            Console.WriteLine("\tNo Types!");
        } else {
            Console.WriteLine("\tFound Types:");
            foreach (Type t in LoadedTypes) {

                if (t.IsPublic && !t.IsEnum && !t.IsValueType) {
                    Console.WriteLine("Type: {0}", t.FullName);
                    PrintConstructorInfo(t);
                }
            }
        }
    }
    private static  void PrintConstructorInfo(Type t) {
        ConstructorInfo[] ctors = t.GetConstructors();
        foreach (ConstructorInfo c in ctors) {
            ParameterInfo[] pList = c.GetParameters();
            if (pList.Length == 0) {
                if (c.IsStatic)
                    Console.WriteLine("\tFound static Constructor.");
                else
                    Console.WriteLine("\tFound default consructor.");
            } else {
                Console.WriteLine("\tConstructor:");
                foreach (ParameterInfo p in pList) {
                    Console.WriteLine("\t\t{0} {1}", p.ParameterType.FullName,p.Name);
                }
            }
        }
    }
}

   
    
    
  








Related examples in the same category

1.Call GetConstructor to get the constructor
2.Invoke in Constructor through ConstructorInfo
3.ConstructorInfo Class Discovers the attributes of a class constructor
4.Searches for a constructor whose parameters match the specified argument types and modifiers
5.Searches for a constructor using the specified binding constraints.
6.Get the constructor that takes an integer as a parameter.
7.Returns all the public constructors defined for the current Type.
8.Get Property/Constructor Info