Print Method Info: BindingFlags : BindingFlags « Reflection « C# / C Sharp






Print Method Info: BindingFlags

  
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);
                    PrintMethodInfo(t);
                }
            }
        }
    }
    private static void PrintMethodInfo(Type t) {
        MethodInfo[] methods = t.GetMethods(BindingFlags.DeclaredOnly |
            BindingFlags.Public | BindingFlags.Instance |
            BindingFlags.Static);
        foreach (MethodInfo m in methods) {
            if (m.IsStatic)
                Console.WriteLine("Static Method: {0}", m.Name);
            else
                Console.WriteLine("Method: {0}", m.Name);
            Console.WriteLine("\tReturns {0}", m.ReturnType.FullName);
            ParameterInfo[] pList = m.GetParameters();
            if (pList.Length == 0) {
                Console.WriteLine("\tNo Parameters");
            } else {
                Console.WriteLine("\tParameter List:");
                foreach (ParameterInfo p in pList) {
                    Console.WriteLine("\t\t{0} {1}", p.ParameterType.FullName,p.Name);
                }
                Console.WriteLine();
            }
        }
    }
}

   
  








Related examples in the same category

1.Use BindingFlags Instance and NonPublic
2.Searches for the constructors defined for the current Type, using the specified BindingFlags.
3.GetConstructors(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance)
4.Using difference BindingFlags to get method
5.BindingFlags.Public | BindingFlags.Instance
6.BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly
7.Get Nested Types with BindingFlags
8.Get Properties with BindingFlags