CodeAttributeDeclaration Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Representerar en attributdeklaration.
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
- Arv
-
CodeAttributeDeclaration
- Attribut
Exempel
I följande kodexempel skapas en CodeAttributeDeclaration som deklarerar en CLSCompliantAttribute med argumentet 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
Kommentarer
A CodeAttributeDeclaration kan användas för att representera ett uttryck som deklarerar ett attribut. Attributnamnet och argumenten för attributet lagras som objektegenskaper. A CodeAttributeArgument kan användas för att representera varje argument för attributet.
Konstruktorer
| Name | Description |
|---|---|
| CodeAttributeDeclaration() |
Initierar en ny instans av CodeAttributeDeclaration klassen. |
| CodeAttributeDeclaration(CodeTypeReference, CodeAttributeArgument[]) |
Initierar en ny instans av klassen med hjälp av CodeAttributeDeclaration den angivna referensen och argumenten för kodtypen. |
| CodeAttributeDeclaration(CodeTypeReference) |
Initierar en ny instans av klassen med hjälp av CodeAttributeDeclaration den angivna kodtypsreferensen. |
| CodeAttributeDeclaration(String, CodeAttributeArgument[]) |
Initierar en ny instans av CodeAttributeDeclaration klassen med det angivna namnet och argumenten. |
| CodeAttributeDeclaration(String) |
Initierar en ny instans av CodeAttributeDeclaration klassen med det angivna namnet. |
Egenskaper
| Name | Description |
|---|---|
| Arguments |
Hämtar argumenten för attributet. |
| AttributeType |
Hämtar kodtypsreferensen för kodattributdeklarationen. |
| Name |
Hämtar eller anger namnet på attributet som deklareras. |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |