C# TypeInfo DeclaringType

Description

TypeInfo DeclaringType Gets the type that declares the current nested type or generic type parameter.

Syntax

TypeInfo.DeclaringType has the following syntax.


public override Type DeclaringType { get; }

Example

This example displays the declaring type of a method in a derived class.


//w w  w. ja v a 2 s .  c o  m
using System;
using System.Reflection;

public abstract class dtype 
{

    public abstract class MyClassA 
    {
        public abstract int m(); 
    }

    public abstract class MyClassB : MyClassA 
    {
    }

    public static void Main(string[] args) 
    { 
        Console.WriteLine("The declaring type of m is {0}.",
            typeof(MyClassB).GetMethod("m").DeclaringType);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo