BindingFlags.DeclaredOnly : BindingFlags « System.Reflection « C# / C Sharp by API






BindingFlags.DeclaredOnly

 

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.BindingFlags.Instance