C# Type DeclaringType

Description

Type DeclaringType gets the type that declares the current nested type or generic type parameter.

Syntax

Type.DeclaringType has the following syntax.


public override Type DeclaringType { get; }

Example

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


/* ww  w  .ja v  a 2 s  . co  m*/
using System;
using System.Reflection;

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

    public abstract class MyClassB : MyClassA 
    {
    }
    
public class MainClass
{
    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 »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version