DynamicMethod.ReturnTypeCustomAttributes Property

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

Gets the custom attributes of the return type for the dynamic method.

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

Syntax

'Declaration
Public Overrides ReadOnly Property ReturnTypeCustomAttributes As ICustomAttributeProvider
public override ICustomAttributeProvider ReturnTypeCustomAttributes { get; }

Property Value

Type: System.Reflection.ICustomAttributeProvider
An ICustomAttributeProvider representing the custom attributes of the return type for the dynamic method.

Remarks

Custom attributes are not supported on the return type of a dynamic method, so the array of custom attributes returned by the GetCustomAttributes method is always empty.

Examples

The following code example shows how to display the custom attributes of the return type of a dynamic method. This code example is part of a larger example provided for the DynamicMethod class.

' ReturnTypeCustomAttributes returns an ICustomeAttributeProvider
' that can be used to enumerate the custom attributes of the
' return value. At present, there is no way to set such custom
' attributes, so the list is empty.
If hello.ReturnType Is GetType(System.Void) Then
   outputBlock.Text &= "The method has no return type." & vbLf
Else
   Dim caProvider As ICustomAttributeProvider = _
       hello.ReturnTypeCustomAttributes
   Dim returnAttributes() As Object = _
       caProvider.GetCustomAttributes(True)
   If returnAttributes.Length = 0 Then
      outputBlock.Text &= "The return type has no custom attributes." & vbLf
   Else
      outputBlock.Text &= "The return type has the following custom attributes:" & vbLf
      For Each attr As Object In returnAttributes
         outputBlock.Text &= "     " & attr.ToString() & vbLf
      Next attr
   End If
End If
// ReturnTypeCustomAttributes returns an ICustomeAttributeProvider
// that can be used to enumerate the custom attributes of the
// return value. At present, there is no way to set such custom
// attributes, so the list is empty.
if (hello.ReturnType == typeof(void))
{
   outputBlock.Text += "The method has no return type." + "\n";
}
else
{
   ICustomAttributeProvider caProvider = hello.ReturnTypeCustomAttributes;
   object[] returnAttributes = caProvider.GetCustomAttributes(true);
   if (returnAttributes.Length == 0)
   {
      outputBlock.Text += "The return type has no custom attributes." + "\n";
   }
   else
   {
      outputBlock.Text += "The return type has the following custom attributes:" + "\n";
      foreach (object attr in returnAttributes)
      {
         outputBlock.Text += "     " + attr.ToString() + "\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.