DynamicMethod.ReturnTypeCustomAttributes Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Obtém os atributos personalizados do tipo de retorno para o método dinâmico.
public:
virtual property System::Reflection::ICustomAttributeProvider ^ ReturnTypeCustomAttributes { System::Reflection::ICustomAttributeProvider ^ get(); };
public override System.Reflection.ICustomAttributeProvider ReturnTypeCustomAttributes { get; }
member this.ReturnTypeCustomAttributes : System.Reflection.ICustomAttributeProvider
Public Overrides ReadOnly Property ReturnTypeCustomAttributes As ICustomAttributeProvider
Valor da propriedade
Um ICustomAttributeProvider que representa os atributos personalizados do tipo de retorno para o método dinâmico.
Exemplos
O exemplo de código a seguir mostra como exibir os atributos personalizados do tipo de retorno de um método dinâmico. Este exemplo de código faz parte de um exemplo maior fornecido para a DynamicMethod classe .
// 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 == Void::typeid)
{
Console::WriteLine("The method has no return type.");
}
else
{
ICustomAttributeProvider^ caProvider = hello->ReturnTypeCustomAttributes;
array<Object^>^ returnAttributes = caProvider->GetCustomAttributes(true);
if (returnAttributes->Length == 0)
{
Console::WriteLine("\r\nThe return type has no custom attributes.");
}
else
{
Console::WriteLine("\r\nThe return type has the following custom attributes:");
for each (Object^ attr in returnAttributes)
{
Console::WriteLine("\t{0}", attr->ToString());
}
}
}
// 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))
{
Console.WriteLine("The method has no return type.");
}
else
{
ICustomAttributeProvider caProvider = hello.ReturnTypeCustomAttributes;
object[] returnAttributes = caProvider.GetCustomAttributes(true);
if (returnAttributes.Length == 0)
{
Console.WriteLine("\r\nThe return type has no custom attributes.");
}
else
{
Console.WriteLine("\r\nThe return type has the following custom attributes:");
foreach( object attr in returnAttributes )
{
Console.WriteLine("\t{0}", attr.ToString());
}
}
}
' 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
Console.WriteLine("The method has no return type.")
Else
Dim caProvider As ICustomAttributeProvider = _
hello.ReturnTypeCustomAttributes
Dim returnAttributes() As Object = _
caProvider.GetCustomAttributes(True)
If returnAttributes.Length = 0 Then
Console.WriteLine(vbCrLf _
& "The return type has no custom attributes.")
Else
Console.WriteLine(vbCrLf _
& "The return type has the following custom attributes:")
For Each attr As Object In returnAttributes
Console.WriteLine(vbTab & attr.ToString())
Next attr
End If
End If
Comentários
Não há suporte para atributos personalizados no tipo de retorno de um método dinâmico, portanto, a matriz de atributos personalizados retornados pelo GetCustomAttributes método está sempre vazia.