DynamicMethod.ReturnTypeCustomAttributes 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得動態方法之傳回類型的自訂屬性。
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
屬性值
ICustomAttributeProvider 表示動態方法之傳回類型的自訂屬性。
範例
下列程式代碼範例示範如何顯示動態方法之傳回型別的自定義屬性。 此程式代碼範例是針對 類別提供的較大範例的 DynamicMethod 一部分。
// 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
備註
動態方法的傳回型別不支援自定義屬性,因此方法傳 GetCustomAttributes 回的自定義屬性陣列一律是空的。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應