Share via


CodeAttributeArgument Sınıf

Tanım

Meta veri öznitelik bildiriminde kullanılan bir 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 kullanımdan kaldırılabilir olduğunu bildirmek için kod öznitelikleri ekler.

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;

int main()
{
    // Declare a new type called Class1.
    CodeTypeDeclaration^ class1 = gcnew CodeTypeDeclaration("Class1");

    // Use attributes to mark the class as serializable and obsolete.
    CodeAttributeDeclaration^ codeAttrDecl =
        gcnew CodeAttributeDeclaration("System.Serializable");
    class1->CustomAttributes->Add(codeAttrDecl);

    CodeAttributeArgument^ codeAttr =
        gcnew CodeAttributeArgument( gcnew CodePrimitiveExpression("This class is obsolete."));
    codeAttrDecl = gcnew 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, gcnew CodeGeneratorOptions());
}

// The CPP code generator produces the following source code for the preceeding example code:
//
//[System.Serializable()]
//[System.Obsolete("This class is obsolete.")]
//public class Class1 {
//}
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ğinin bir özelliğinin başlatıldığı değeri göstermek 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.

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

CodeAttributeArgument()

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

CodeAttributeArgument(CodeExpression)

Belirtilen değeri kullanarak sınıfının yeni bir örneğini CodeAttributeArgument 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

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

Value

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

Yöntemler

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()

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

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

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

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

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

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.