Поделиться через


DynamicMethod.DeclaringType Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the type that declares the method, which is always nulla null reference (Nothing in Visual Basic) for dynamic methods.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides ReadOnly Property DeclaringType As Type
public override Type DeclaringType { get; }

Property Value

Type: System.Type
Always nulla null reference (Nothing in Visual Basic).

Remarks

This property always returns nulla null reference (Nothing in Visual Basic) for dynamic methods. Even when a dynamic method is logically associated with a type, it is not declared by the type.

Examples

The following code example displays the declaring type of a dynamic method. This code example is part of a larger example provided for the DynamicMethod class.

' Display the declaring type, which is always Nothing for dynamic
' methods.
If hello.DeclaringType Is Nothing Then
   outputBlock.Text &= "DeclaringType is always Nothing for dynamic methods." & vbLf
Else
   outputBlock.Text += String.Format("DeclaringType: {0}", hello.DeclaringType) & vbLf
End If
// Display the declaring type, which is always null for dynamic
// methods.
if (hello.DeclaringType == null)
{
   outputBlock.Text += "DeclaringType is always null for dynamic methods." + "\n";
}
else
{
   outputBlock.Text += String.Format("DeclaringType: {0}", hello.DeclaringType) + "\n";
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.