GeneratedCodeAttribute Kelas

Definisi

Mengidentifikasi kode yang dihasilkan oleh alat. Kelas ini tidak dapat diwariskan.

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
Warisan
GeneratedCodeAttribute
Atribut

Contoh

Contoh kode berikut menunjukkan penggunaan GeneratedCodeAttribute kelas untuk mengidentifikasi kode yang dihasilkan 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

Keterangan

Kelas GeneratedCodeAttribute dapat digunakan oleh alat analisis kode untuk mengidentifikasi kode yang dihasilkan komputer, dan untuk memberikan analisis berdasarkan alat dan versi alat yang menghasilkan kode.

Konstruktor

GeneratedCodeAttribute(String, String)

Menginisialisasi instans GeneratedCodeAttribute baru kelas yang menentukan nama dan versi alat yang menghasilkan kode.

Properti

Tool

Mendapatkan nama alat yang menghasilkan kode.

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)
Version

Mendapatkan versi alat yang menghasilkan kode.

Metode

Equals(Object)

Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
GetHashCode()

Mengembalikan kode hash untuk instans ini.

(Diperoleh dari Attribute)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk