C# MemberInfo DeclaringType
Description
MemberInfo DeclaringType
Gets the class that declares
this member.
Syntax
MemberInfo.DeclaringType
has the following syntax.
public abstract Type DeclaringType { get; }
Example
using System;/*from w ww . j a va 2 s . c o m*/
using System.IO;
using System.Reflection;
namespace MyNamespace1
{
interface i
{
int MyVar() ;
};
// DeclaringType for MyVar is i.
class A : i
{
public int MyVar() { return 0; }
};
// DeclaringType for MyVar is A.
class B : A
{
new int MyVar() { return 0; }
};
// DeclaringType for MyVar is B.
class C : A
{
};
// DeclaringType for MyVar is A.
}
namespace MyNamespace2
{
class Mymemberinfo
{
public static void Main(string[] args)
{
Type MyType =Type.GetType("System.IO.BufferedStream");
MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
Console.WriteLine(MyType.FullName);
foreach (MemberInfo Mymemberinfo in Mymemberinfoarray)
{
Console.WriteLine(Mymemberinfo.DeclaringType);
}
}
}
}
namespace MyNamespace3
{
class A
{
virtual public void M () {}
}
class B: A
{
override public void M () {}
}
}
The code above generates the following result.