CodeAttributeDeclaration 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.
Attribútumdeklarációt jelöl.
public ref class CodeAttributeDeclaration
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttributeDeclaration
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeAttributeDeclaration = class
Public Class CodeAttributeDeclaration
- Öröklődés
-
CodeAttributeDeclaration
- Attribútumok
Példák
Az alábbi példakód létrehoz egy CodeAttributeDeclaration olyan kódot, amely egy argumentummal deklarálja CLSCompliantAttribute a következőt false:
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");
// Declare a new code attribute
CodeAttributeDeclaration codeAttrDecl = new CodeAttributeDeclaration(
"System.CLSCompliantAttribute",
new CodeAttributeArgument(new CodePrimitiveExpression(false)));
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.CLSCompliantAttribute(false)]
// 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")
' Declare a new code attribute
Dim codeAttrDecl As New CodeAttributeDeclaration(
"System.CLSCompliantAttribute",
new CodeAttributeArgument(new CodePrimitiveExpression(false)))
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.CLSCompliantAttribute(false)> _
' Public Class Class1
' End Class
Megjegyzések
Egy CodeAttributeDeclaration attribútumot deklaráló kifejezés ábrázolására használható. Az attribútum neve és az attribútum argumentumai az objektum tulajdonságaiként vannak tárolva. Az A CodeAttributeArgument az attribútum minden argumentumának ábrázolására használható.
Konstruktorok
| Name | Description |
|---|---|
| CodeAttributeDeclaration() |
Inicializálja a CodeAttributeDeclaration osztály új példányát. |
| CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[]) |
Inicializálja az osztály új példányát a CodeAttributeDeclaration megadott kódtípus-hivatkozással és argumentumokkal. |
| CodeAttributeDeclaration(CodeTypeReference) |
Inicializálja az osztály új példányát a CodeAttributeDeclaration megadott kódtípus-hivatkozással. |
| CodeAttributeDeclaration(String, CodeAttributeArgument[]) |
Inicializálja az CodeAttributeDeclaration osztály új példányát a megadott névvel és argumentumokkal. |
| CodeAttributeDeclaration(String) |
Inicializálja az CodeAttributeDeclaration osztály új példányát a megadott névvel. |
Tulajdonságok
| Name | Description |
|---|---|
| Arguments |
Lekéri az attribútum argumentumait. |
| AttributeType |
Lekéri a kódattribútum-deklaráció kódtípus-referenciáját. |
| Name |
Lekéri vagy beállítja a deklarált attribútum nevé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) |