AttributeTargets 열거형

정의

특성을 적용하는 데 유효한 애플리케이션 요소를 지정합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class AttributeTargets
[System.Flags]
public enum AttributeTargets
[System.Flags]
[System.Serializable]
public enum AttributeTargets
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum AttributeTargets
[<System.Flags>]
type AttributeTargets = 
[<System.Flags>]
[<System.Serializable>]
type AttributeTargets = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type AttributeTargets = 
Public Enum AttributeTargets
상속
AttributeTargets
특성

필드

All 32767

특성은 모든 애플리케이션 요소에 적용할 수 있습니다.

Assembly 1

특성은 어셈블리에 적용할 수 있습니다.

Class 4

특성은 클래스에 적용할 수 있습니다.

Constructor 32

특성은 생성자에 적용할 수 있습니다.

Delegate 4096

특성은 대리자에 적용할 수 있습니다.

Enum 16

특성은 열거형에 적용할 수 있습니다.

Event 512

특성은 이벤트에 적용할 수 있습니다.

Field 256

특성은 필드에 적용할 수 있습니다.

GenericParameter 16384

특성은 제네릭 매개 변수에 적용할 수 있습니다. 현재 이 특성은 C#, MSIL(Microsoft Intermediate language) 및 내보낸 코드에만 적용할 수 있습니다.

Interface 1024

특성은 인터페이스에 적용할 수 있습니다.

Method 64

특성은 메서드에 적용할 수 있습니다.

Module 2

특성은 모듈에 적용할 수 있습니다. Module은 Visual Basic 표준 모듈이 아니라 이식 가능 파일(.dll 또는 .exe)을 나타냅니다.

Parameter 2048

특성은 매개 변수에 적용할 수 있습니다.

Property 128

특성은 속성에 적용할 수 있습니다.

ReturnValue 8192

특성은 반환 값에 적용할 수 있습니다.

Struct 8

특성은 구조체 즉, 값 형식에 적용할 수 있습니다.

예제

다음 예제에서는 다양한 대상에 특성을 적용하는 방법을 보여 줍니다.

참고

Visual Basic 및 Visual c + + 구문에 현재 형식 매개 변수 특성의 애플리케이션을 지원 하지 않습니다.

using namespace System;

namespace AttTargsCS
{

   // This attribute is only valid on a class.

   [AttributeUsage(AttributeTargets::Class)]
   public ref class ClassTargetAttribute: public Attribute{};


   // This attribute is only valid on a method.

   [AttributeUsage(AttributeTargets::Method)]
   public ref class MethodTargetAttribute: public Attribute{};


   // This attribute is only valid on a constructor.

   [AttributeUsage(AttributeTargets::Constructor)]
   public ref class ConstructorTargetAttribute: public Attribute{};


   // This attribute is only valid on a field.

   [AttributeUsage(AttributeTargets::Field)]
   public ref class FieldTargetAttribute: public Attribute{};


   // This attribute is valid on a class or a method.

   [AttributeUsage(AttributeTargets::Class|AttributeTargets::Method)]
   public ref class ClassMethodTargetAttribute: public Attribute{};


   // This attribute is valid on any target.

   [AttributeUsage(AttributeTargets::All)]
   public ref class AllTargetsAttribute: public Attribute{};


   [ClassTarget]
   [ClassMethodTarget]
   [AllTargets]
   public ref class TestClassAttribute
   {
   private:

      [ConstructorTarget]
      [AllTargets]
      TestClassAttribute(){}


   public:

      [MethodTarget]
      [ClassMethodTarget]
      [AllTargets]
      void Method1(){}


      [FieldTarget]
      [AllTargets]
      int myInt;
      static void Main(){}

   };

}
using System;

namespace AttTargsCS {
    // This attribute is only valid on a class.
    [AttributeUsage(AttributeTargets.Class)]
    public class ClassTargetAttribute : Attribute {
    }

    // This attribute is only valid on a method.
    [AttributeUsage(AttributeTargets.Method)]
    public class MethodTargetAttribute : Attribute {
    }

    // This attribute is only valid on a constructor.
    [AttributeUsage(AttributeTargets.Constructor)]
    public class ConstructorTargetAttribute : Attribute {
    }

    // This attribute is only valid on a field.
    [AttributeUsage(AttributeTargets.Field)]
    public class FieldTargetAttribute : Attribute {
    }

    // This attribute is valid on a class or a method.
    [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method)]
    public class ClassMethodTargetAttribute : Attribute {
    }

    // This attribute is valid on a generic type parameter.
    [AttributeUsage(AttributeTargets.GenericParameter)]
    public class GenericParameterTargetAttribute : Attribute {
    }

    // This attribute is valid on any target.
    [AttributeUsage(AttributeTargets.All)]
    public class AllTargetsAttribute : Attribute {
    }

    [ClassTarget]
    [ClassMethodTarget]
    [AllTargets]
    public class TestClassAttribute {
        [ConstructorTarget]
        [AllTargets]
        TestClassAttribute() {
        }

        [MethodTarget]
        [ClassMethodTarget]
        [AllTargets]
        public void Method1() {
        }

        [FieldTarget]
        [AllTargets]
        public int myInt;

        public void GenericMethod<
            [GenericParameterTarget, AllTargets] T>(T x) {
        }

        static void Main(string[] args) {
        }
    }
}
open System

// This attribute is only valid on a class.
[<AttributeUsage(AttributeTargets.Class)>]
type ClassTargetAttribute() =
    inherit Attribute()

// This attribute is only valid on a method.
[<AttributeUsage(AttributeTargets.Method)>]
type MethodTargetAttribute() =
    inherit Attribute()

// This attribute is only valid on a constructor.
[<AttributeUsage(AttributeTargets.Constructor)>]
type ConstructorTargetAttribute() =
    inherit Attribute()

// This attribute is only valid on a field.
[<AttributeUsage(AttributeTargets.Field)>]
type FieldTargetAttribute() =
    inherit Attribute()

// This attribute is valid on a class or a method.
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Method)>]
type ClassMethodTargetAttribute() =
    inherit Attribute()

// This attribute is valid on a generic type parameter.
[<AttributeUsage(AttributeTargets.GenericParameter)>]
type GenericParameterTargetAttribute() =
    inherit Attribute()

// This attribute is valid on any target.
[<AttributeUsage(AttributeTargets.All)>]
type AllTargetsAttribute() =
    inherit Attribute()

[<ClassTarget>]
[<ClassMethodTarget>]
[<AllTargets>]
type TestClassAttribute [<ConstructorTarget>] [<AllTargets>] () =
    [<FieldTarget>]
    [<AllTargets>]
    let myInt = 0

    [<MethodTarget>]
    [<ClassMethodTarget>]
    [<AllTargets>]
    member _.Method1() = ()

    member _.GenericMethod<[<GenericParameterTarget; AllTargets>] 'T>(x: 'T) = ()
Module DemoModule
    ' This attribute is only valid on a class.
    <AttributeUsage(AttributeTargets.Class)> _
    Public Class ClassTargetAttribute
        Inherits Attribute
    End Class

    ' This attribute is only valid on a method.
    <AttributeUsage(AttributeTargets.Method)> _
    Public Class MethodTargetAttribute
        Inherits Attribute
    End Class

    ' This attribute is only valid on a constructor.
    <AttributeUsage(AttributeTargets.Constructor)> _
    Public Class ConstructorTargetAttribute 
        Inherits Attribute
    End Class

    ' This attribute is only valid on a field.
    <AttributeUsage(AttributeTargets.Field)> _
    Public Class FieldTargetAttribute 
        Inherits Attribute
    End Class

    ' This attribute is valid on a class or a method.
    <AttributeUsage(AttributeTargets.Class Or AttributeTargets.Method)> _
    Public Class ClassMethodTargetAttribute 
        Inherits Attribute
    End Class

    ' This attribute is valid on any target.
    <AttributeUsage(AttributeTargets.All)> _
    Public Class AllTargetsAttribute 
        Inherits Attribute
    End Class

    <ClassTarget, _
    ClassMethodTarget, _
    AllTargets> _
    Public Class TestClassAttribute
        <ConstructorTarget, _
        AllTargets> _
        Public Sub New
        End Sub

        <MethodTarget, _
        ClassMethodTarget, _
        AllTargets> _
        Public Sub Method1()
        End Sub

        <FieldTarget, _
        AllTargets> _
        Public myInt as Integer
    End Class

    Sub Main()
    End Sub
End Module

설명

클래스는 AttributeUsageAttribute 이 열거형을 사용하여 특성을 적용하는 데 유효한 요소의 종류를 지정합니다.

AttributeTargets 열거형 값을 비트 OR 연산과 결합하여 기본 조합을 가져올 수 있습니다.

적용 대상

추가 정보