CodeAttributeArgument Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Metaadat-attribútum deklarációjában használt argumentumot jelöl.
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
- Öröklődés
-
CodeAttributeArgument
- Attribútumok
Példák
Az alábbi kód létrehoz egy osztályt, és kódattribútumokat ad hozzá annak deklarálásához, hogy az osztály szerializálható és elavult.
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
Megjegyzések
CodeAttributeArgument Egy attribútumkonstruktor egyetlen argumentumának értékét, vagy egy olyan értéket jelölhet, amellyel inicializálni szeretné az attribútum egyik tulajdonságát.
A Value tulajdonság az argumentum értékét jelzi. A Name tulajdonság használata esetén annak az attribútumnak a nevét jelzi, amelyhez hozzá szeretné rendelni az értéket.
Az attribútumdeklarációkat gyakran inicializálják számos argumentummal, amelyeket a rendszer futtatáskor ad át az attribútum konstruktorának. Ha argumentumokat szeretne megadni egy attribútum konstruktorának, adjon hozzá minden CodeAttributeArgument argumentumot egy Arguments gyűjteményhez CodeAttributeDeclaration. Csak az Value egyes CodeAttributeArgument tulajdonságokat kell inicializálni. A gyűjteményben lévő argumentumok sorrendjének meg kell felelnie az attribútum konstruktorának metódusa aláírásában szereplő argumentumok sorrendjének.
A konstruktoron CodeAttributeArgument keresztül nem elérhető attribútum tulajdonságait úgy is beállíthatja, hogy megadja a beállítandó tulajdonság nevét és a beállítandó értéket.
Konstruktorok
| Name | Description |
|---|---|
| CodeAttributeArgument() |
Inicializálja a CodeAttributeArgument osztály új példányát. |
| CodeAttributeArgument(CodeExpression) |
Inicializálja az osztály új példányát CodeAttributeArgument a megadott érték használatával. |
| CodeAttributeArgument(String, CodeExpression) |
Inicializálja az CodeAttributeArgument osztály új példányát a megadott név és érték használatával. |
Tulajdonságok
| Name | Description |
|---|---|
| Name |
Lekéri vagy beállítja az attribútum nevét. |
| Value |
Lekéri vagy beállítja az attribútumargumentum értékét. |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal. (Öröklődés forrása Object) |
| GetHashCode() |
Ez az alapértelmezett kivonatoló függvény. (Öröklődés forrása Object) |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |