GeneratedCodeAttribute 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.
Identyfikuje kod wygenerowany przez narzędzie. Klasa ta nie może być dziedziczona.
public ref class GeneratedCodeAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=false, Inherited=false)]
public sealed class GeneratedCodeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=false, Inherited=false)>]
type GeneratedCodeAttribute = class
inherit Attribute
Public NotInheritable Class GeneratedCodeAttribute
Inherits Attribute
- Dziedziczenie
- Atrybuty
Poniższy przykład kodu przedstawia użycie klasy do identyfikowania kodu wygenerowanego GeneratedCodeAttribute przez komputer.
#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 generated code attribute
GeneratedCodeAttribute^ generatedCodeAttribute =
gcnew GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0");
// Use the generated code attribute members in the attribute declaration
CodeAttributeDeclaration^ codeAttrDecl =
gcnew CodeAttributeDeclaration(generatedCodeAttribute->GetType()->Name,
gcnew CodeAttributeArgument(
gcnew CodePrimitiveExpression(generatedCodeAttribute->Tool)),
gcnew CodeAttributeArgument(
gcnew CodePrimitiveExpression(generatedCodeAttribute->Version)));
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:
//
// [GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0")]
// 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 generated code attribute
GeneratedCodeAttribute generatedCodeAttribute =
new GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0");
// Use the generated code attribute members in the attribute declaration
CodeAttributeDeclaration codeAttrDecl =
new CodeAttributeDeclaration(generatedCodeAttribute.GetType().Name,
new CodeAttributeArgument(
new CodePrimitiveExpression(generatedCodeAttribute.Tool)),
new CodeAttributeArgument(
new CodePrimitiveExpression(generatedCodeAttribute.Version)));
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:
//
// [GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0")]
// 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 generated code attribute
Dim generatedCodeAttribute As _
New GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0")
' Use the generated code attribute members in the attribute declaration
Dim codeAttrDecl As _
New CodeAttributeDeclaration(generatedCodeAttribute.GetType().Name,
New CodeAttributeArgument(
New CodePrimitiveExpression(generatedCodeAttribute.Tool)),
New CodeAttributeArgument(
New CodePrimitiveExpression(generatedCodeAttribute.Version)))
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:
'
' <GeneratedCodeAttribute("SampleCodeGenerator", "2.0.0.0")> _
' Public Class Class1
' End Class
Klasa GeneratedCodeAttribute może być używana przez narzędzia do analizy kodu do identyfikowania kodu generowanego przez komputer oraz do udostępniania analizy na podstawie narzędzia i wersji narzędzia, które wygenerowało kod.
Generated |
Inicjuje GeneratedCodeAttribute nowe wystąpienie klasy, określając nazwę i wersję narzędzia, które wygenerowało kod. |
Tool |
Pobiera nazwę narzędzia, które wygenerowało kod. |
Type |
Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu . (Odziedziczone po Attribute) |
Version |
Pobiera wersję narzędzia, które wygenerowało kod. |
Equals(Object) |
Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi. (Odziedziczone po Attribute) |
Get |
Zwraca wartość skrótu dla tego wystąpienia. (Odziedziczone po Attribute) |
Get |
Type Pobiera wartość bieżącego wystąpienia. (Odziedziczone po Object) |
Is |
Podczas zastępowania w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną dla klasy pochodnej. (Odziedziczone po Attribute) |
Match(Object) |
Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi. (Odziedziczone po Attribute) |
Memberwise |
Tworzy płytkią kopię bieżącego Objectelementu . (Odziedziczone po Object) |
To |
Zwraca ciąg reprezentujący bieżący obiekt. (Odziedziczone po Object) |
_Attribute. |
Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania. (Odziedziczone po Attribute) |
_Attribute. |
Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu. (Odziedziczone po Attribute) |
_Attribute. |
Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1). (Odziedziczone po Attribute) |
_Attribute. |
Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt. (Odziedziczone po Attribute) |
Produkt | Wersje |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 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 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Opinia o produkcie .NET
.NET to projekt typu open source. Wybierz link, aby przekazać opinię: