AttributeUsageAttribute(AttributeTargets) 建構函式

定義

使用指定的 AttributeUsageAttribute 清單、AttributeTargets 值和 AllowMultiple 值,初始化 Inherited 類別的新執行個體。

public:
 AttributeUsageAttribute(AttributeTargets validOn);
public AttributeUsageAttribute (AttributeTargets validOn);
new AttributeUsageAttribute : AttributeTargets -> AttributeUsageAttribute
Public Sub New (validOn As AttributeTargets)

參數

validOn
AttributeTargets

使用位元的 OR 運算所結合的數值集,用來指示那個程式項目有效。

範例

DispId 屬性的定義說明如何使用位 OR 運算來合併數個 AttributeTargets 值。

namespace InteropServices
{
   [AttributeUsage(AttributeTargets::Method|
   AttributeTargets::Field|
   AttributeTargets::Property)
   ]
   public ref class DispIdAttribute: public Attribute
   {
   public:
      DispIdAttribute( int value )
      {
         // . . .
      }

      property int Value 
      {
         int get()
         {
            // . . .
            return 0;
         }
      }
   };
}
namespace System.Runtime.InteropServices
{
   [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field |
    AttributeTargets.Property)]
   public class DispIdAttribute: System.Attribute
   {
      public DispIdAttribute(int value) {
        // . . .
      }

      public int Value {
         get {
            // . . .
            return 0;
         }
      }
   }
}
namespace System.Runtime.InteropServices

open System

[<AttributeUsage(AttributeTargets.Method ||| AttributeTargets.Field ||| AttributeTargets.Property)>]
type DispIdAttribute(value: int) =
    inherit Attribute()
      
    // . . .

    member _.Value with get() = 
        // . . .
        0
Namespace System.Runtime.InteropServices
    
    <AttributeUsage(AttributeTargets.Method _
        Or AttributeTargets.Field _
        Or AttributeTargets.Property)> _    
    Public Class DispIdAttribute    
        Inherits System.Attribute
        
        Public Sub New(value As Integer)
            ' . . .
        End Sub
        
        Public ReadOnly Property Value() As Integer
            Get
                ' . . .
                Return 0
            End Get
        End Property
    End Class
End Namespace

備註

您可以 AttributeTargets 使用位 or 運算來合併數個值,以取得所需的有效程式元素組合。

如需預設的屬性值,請參閱 ValidOnAllowMultipleInherited 屬性。

適用於

另請參閱