CodeAttributeArgument 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
메타데이터 특성 선언에 사용되는 인수를 나타냅니다.
public ref class CodeAttributeArgument
public class CodeAttributeArgument
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttributeArgument
type CodeAttributeArgument = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeAttributeArgument = class
Public Class CodeAttributeArgument
- 상속
-
CodeAttributeArgument
- 특성
예제
다음 코드는 클래스를 만들고 코드 특성을 추가하여 클래스가 직렬화 가능하고 사용되지 않음을 선언합니다.
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
public class CodeGenExample
{
static void Main()
{
// Declare a new type called Class1.
CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");
// Use attributes to mark the class as serializable and obsolete.
CodeAttributeDeclaration codeAttrDecl =
new CodeAttributeDeclaration("System.Serializable");
class1.CustomAttributes.Add(codeAttrDecl);
CodeAttributeArgument codeAttr =
new CodeAttributeArgument( new CodePrimitiveExpression("This class is obsolete."));
codeAttrDecl = new CodeAttributeDeclaration("System.Obsolete", codeAttr);
class1.CustomAttributes.Add(codeAttrDecl);
// Create a C# code provider
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
// Generate code and send the output to the console
provider.GenerateCodeFromType(class1, Console.Out, new CodeGeneratorOptions());
}
}
// The C# code generator produces the following source code for the preceeding example code:
//
// [System.Serializable()]
// [System.Obsolete("This class is obsolete.")]
// public class Class1 {
// }
Imports System.CodeDom
Imports System.CodeDom.Compiler
Public Class CodeGenExample
Shared Sub Main
' Declare a new type called Class1.
Dim class1 as New CodeTypeDeclaration("Class1")
' Use attributes to mark the class as serializable and obsolete.
Dim codeAttrDecl As New CodeAttributeDeclaration("System.Serializable")
class1.CustomAttributes.Add(codeAttrDecl)
Dim codeAttr As _
New CodeAttributeArgument( new CodePrimitiveExpression("This class is obsolete."))
codeAttrDecl = New CodeAttributeDeclaration("System.Obsolete", codeAttr)
class1.CustomAttributes.Add(codeAttrDecl)
' Create a Visual Basic code provider
Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")
' Generate code and send the output to the console
provider.GenerateCodeFromType(class1, Console.Out, New CodeGeneratorOptions())
End Sub
End Class
' The Visual Basic code generator produces the following source code for the preceeding example code:
'
' <System.Serializable(), _
' System.Obsolete("This class is obsolete.")> _
' Public Class Class1
' End Class
설명
CodeAttributeArgument 는 특성 생성자의 단일 인수에 대한 값 또는 특성의 속성을 초기화할 값을 나타내는 데 사용할 수 있습니다.
이 속성은 Value 인수의 값을 나타냅니다. 사용할 경우 속성은 Name 값을 할당할 특성의 속성 이름을 나타냅니다.
특성 선언은 런타임에 특성 생성자에 전달되는 여러 인수를 사용하여 자주 초기화됩니다. 특성의 생성자에 인수를 제공하려면 각 인수에 대한 인수를 해당 컬렉션CodeAttributeDeclaration에 Arguments 추가 CodeAttributeArgument 합니다. Value 각 CodeAttributeArgument 속성만 초기화해야 합니다. 컬렉션 내의 인수 순서는 특성에 대한 생성자의 메서드 서명에 있는 인수 순서에 해당해야 합니다.
설정할 속성의 이름과 설정할 값을 제공하여 CodeAttributeArgument 생성자를 통해 사용할 수 없는 특성의 속성을 설정할 수도 있습니다.
생성자
| Name | Description |
|---|---|
| CodeAttributeArgument() |
CodeAttributeArgument 클래스의 새 인스턴스를 초기화합니다. |
| CodeAttributeArgument(CodeExpression) |
지정된 값을 사용하여 클래스의 CodeAttributeArgument 새 인스턴스를 초기화합니다. |
| CodeAttributeArgument(String, CodeExpression) |
지정된 이름과 값을 사용하여 클래스의 CodeAttributeArgument 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Name |
특성의 이름을 가져오거나 설정합니다. |
| Value |
특성 인수의 값을 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |