C# EventInfo DeclaringType

Description

EventInfo DeclaringType Gets the class that declares this member.

Syntax

EventInfo.DeclaringType has the following syntax.


public abstract Type DeclaringType { get; }

Example

The following example shows how DeclaringType works with classes and interfaces and retrieves the member names of the System.IO.BufferedStream class, along with the class in which those members are declared.


using System;// ww  w .  ja  v a2  s . c om
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("\nThere are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName); 
            foreach (MemberInfo Mymemberinfo in Mymemberinfoarray) 
            {  
                Console.WriteLine("Declaring type of {0} is {1}.", Mymemberinfo.Name, Mymemberinfo.DeclaringType); 
            }
        }
    }
}

namespace MyNamespace3 
{
    class A 
    {
        virtual public void M () {}
    }
    class B: A 
    {
        override public void M () {}
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo