MemberInfo.DeclaringType Property gets the class that declares this member.
using System;
using System.IO;
using System.Reflection;
interface i
{
int MyVar();
};
class A : i
{
public int MyVar() { return 0; }
};
class B : A
{
new int MyVar() { return 0; }
};
class C : A
{
};
class Mymemberinfo
{
public static void Main(string[] args)
{
Type MyType =Type.GetType("System.IO.BufferedStream");
MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
Console.WriteLine(Mymemberinfoarray.Length);
Console.WriteLine(MyType.FullName);
foreach (MemberInfo Mymemberinfo in Mymemberinfoarray)
{
Console.WriteLine("Declaring type of {0} is {1}.", Mymemberinfo.Name, Mymemberinfo.DeclaringType);
}
}
}
Related examples in the same category