Aracılığıyla paylaş


CodeAttributeArgument Sınıf

Tanım

Meta veri öznitelik bildiriminde kullanılan bağımsız değişkeni temsil eder.

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
Devralma
CodeAttributeArgument
Öznitelikler

Örnekler

Aşağıdaki kod bir sınıf oluşturur ve sınıfın serileştirilebilir ve eski olduğunu bildirmek için kod öznitelikleri ekler.

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

Açıklamalar

CodeAttributeArgument bir öznitelik oluşturucusunun tek bir bağımsız değişkeninin değerini veya özniteliğin özelliğinin başlatılacağı değeri temsil etmek için kullanılabilir.

Value özelliği, bağımsız değişkenin değerini gösterir. Name özelliği kullanıldığında, değerin atandığı özniteliğin özelliğinin adını gösterir.

Öznitelik bildirimleri genellikle çalışma zamanında özniteliğin oluşturucusuna geçirilen bir dizi bağımsız değişkenle başlatılır. Bir özniteliğin oluşturucusunun bağımsız değişkenlerini sağlamak için, bir koleksiyonuna Arguments her bağımsız değişken için bir CodeAttributeDeclarationekleyinCodeAttributeArgument. Value Yalnızca her CodeAttributeArgument birinin özelliğinin başlatılması gerekir. Koleksiyondaki bağımsız değişkenlerin sırası, özniteliğinin oluşturucusunun yöntem imzasında yer alan bağımsız değişkenlerin sırasına karşılık gelir.

Ayrıca, ayarlanacağı özelliğin adını ve ayarlanacağı değeri belirterek CodeAttributeArgument oluşturucu aracılığıyla kullanılamayan özniteliğin özelliklerini de ayarlayabilirsiniz.

Oluşturucular

Name Description
CodeAttributeArgument()

CodeAttributeArgument sınıfının yeni bir örneğini başlatır.

CodeAttributeArgument(CodeExpression)

Belirtilen değeri kullanarak sınıfın CodeAttributeArgument yeni bir örneğini başlatır.

CodeAttributeArgument(String, CodeExpression)

Belirtilen ad ve değeri kullanarak sınıfın CodeAttributeArgument yeni bir örneğini başlatır.

Özellikler

Name Description
Name

Özniteliğin adını alır veya ayarlar.

Value

Öznitelik bağımsız değişkeninin değerini alır veya ayarlar.

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.