CodeAttributeDeclaration Klasa
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Reprezentuje deklarację atrybutu.
public ref class CodeAttributeDeclaration
public class CodeAttributeDeclaration
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeAttributeDeclaration
type CodeAttributeDeclaration = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeAttributeDeclaration = class
Public Class CodeAttributeDeclaration
- Dziedziczenie
-
CodeAttributeDeclaration
- Atrybuty
Poniższy przykład kodu tworzy obiekt CodeAttributeDeclaration , który deklaruje CLSCompliantAttribute element z argumentem false
:
#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");
// Declare a new code attribute
CodeAttributeDeclaration^ codeAttrDecl = gcnew CodeAttributeDeclaration(
"System.CLSCompliantAttribute",
gcnew CodeAttributeArgument(gcnew 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, gcnew CodeGeneratorOptions());
}
// The CPP code generator produces the following source code for the preceeding example code:
//
//[System.CLSCompliantAttribute(false)]
//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");
// 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
Element CodeAttributeDeclaration może służyć do reprezentowania wyrażenia, które deklaruje atrybut. Nazwa atrybutu i argumenty atrybutu są przechowywane jako właściwości obiektu. Element CodeAttributeArgument może służyć do reprezentowania każdego argumentu dla atrybutu.
Code |
Inicjuje nowe wystąpienie klasy CodeAttributeDeclaration. |
Code |
Inicjuje CodeAttributeDeclaration nowe wystąpienie klasy przy użyciu określonego odwołania typu kodu. |
Code |
Inicjuje CodeAttributeDeclaration nowe wystąpienie klasy przy użyciu odwołania do określonego typu kodu i argumentów. |
Code |
Inicjuje CodeAttributeDeclaration nowe wystąpienie klasy przy użyciu określonej nazwy. |
Code |
Inicjuje CodeAttributeDeclaration nowe wystąpienie klasy przy użyciu określonej nazwy i argumentów. |
Arguments |
Pobiera argumenty atrybutu. |
Attribute |
Pobiera odwołanie do typu kodu dla deklaracji atrybutu kodu. |
Name |
Pobiera lub ustawia nazwę zadeklarowanego atrybutu. |
Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Odziedziczone po Object) |
Get |
Służy jako domyślna funkcja skrótu. (Odziedziczone po Object) |
Get |
Type Pobiera bieżące wystąpienie. (Odziedziczone po Object) |
Memberwise |
Tworzy płytkią kopię bieżącego Objectelementu . (Odziedziczone po Object) |
To |
Zwraca ciąg reprezentujący bieżący obiekt. (Odziedziczone po Object) |
Produkt | Wersje |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: