Use BindingFlags Instance and NonPublic : BindingFlags « Reflection « C# / C Sharp






Use BindingFlags Instance and NonPublic

 

using System;
using System.Reflection;

class DumpType {
    public static void Main() {
        MyClass zObj = new MyClass();
        Type tObj = zObj.GetType();
        MemberInfo[] members = tObj.GetMembers(BindingFlags.Instance | BindingFlags.NonPublic);
        foreach (MemberInfo member in members) {
            Console.WriteLine(member.Name);
        }
        members = tObj.GetMembers(BindingFlags.Public | BindingFlags.Static);

        Console.WriteLine(" ");
        foreach (MemberInfo member in members) {
            Console.WriteLine(member.Name);
        }
    }
}

class MyClass {
    private int vara = 5;
    public int PropA {
        get {
            return vara;
        }
    }
    static public void MethodA() {
        Console.WriteLine("MyClass::MethodA called.");
    }
}
           
         
  








Related examples in the same category

1.Print Method Info: BindingFlags
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