Get parameter information by using ConstructorInfo and ParameterInfo : ConstructorInfo : Reflection C# Source Code


Custom Search

C# Source Code » Reflection » ConstructorInfo »

 

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);
                }
            }
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Reflection
» ConstructorInfo