Bagikan melalui


CodeTypeReference Kelas

Definisi

Mewakili referensi ke jenis.

public ref class CodeTypeReference : System::CodeDom::CodeObject
public class CodeTypeReference : System.CodeDom.CodeObject
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeTypeReference : System.CodeDom.CodeObject
type CodeTypeReference = class
    inherit CodeObject
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeTypeReference = class
    inherit CodeObject
Public Class CodeTypeReference
Inherits CodeObject
Warisan
CodeTypeReference
Atribut

Contoh

Contoh berikut menunjukkan penggunaan untuk CodeTypeReference mewakili referensi ke jenis.

// Creates a reference to the System.DateTime type.
CodeTypeReference^ typeRef1 = gcnew CodeTypeReference("System.DateTime");

// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression^ typeof1 = gcnew CodeTypeOfExpression(typeRef1);

// Create a C# code provider
CodeDomProvider^ provider = CodeDomProvider::CreateProvider("CSharp");

// Generate code and send the output to the console
provider->GenerateCodeFromExpression(typeof1, Console::Out, gcnew CodeGeneratorOptions());
// The code generator produces the following source code for the preceeding example code:
//    typeof(System.DateTime)
// Creates a reference to the System.DateTime type.
CodeTypeReference typeRef1 = new CodeTypeReference("System.DateTime");

// Creates a typeof expression for the specified type reference.
CodeTypeOfExpression typeof1 = new CodeTypeOfExpression(typeRef1);

// Create a C# code provider
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

// Generate code and send the output to the console
provider.GenerateCodeFromExpression(typeof1, Console.Out, new CodeGeneratorOptions());
// The code generator produces the following source code for the preceeding example code:
//    typeof(System.DateTime)
' Creates a reference to the System.DateTime type.
Dim typeRef1 As New CodeTypeReference("System.DateTime")

' Creates a typeof expression for the specified type reference.
Dim typeof1 As New CodeTypeOfExpression(typeRef1)

' Create a Visual Basic code provider
Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider("VisualBasic")

' Generate code and send the output to the console
provider.GenerateCodeFromExpression(typeof1, Console.Out, new CodeGeneratorOptions())
' The code generator produces the following source code for the preceeding example code:
'    GetType(Date)

Keterangan

Objek CodeTypeReference digunakan untuk mewakili jenis untuk objek CodeDOM. Ketika jenis CodeDOM memiliki Type properti , jenisnya adalah CodeTypeReference. Misalnya, CodeMemberField.Type properti adalah CodeTypeReference yang mewakili jenis data bidang.

CodeTypeReference dapat diinisialisasi dengan Type objek atau string. Umumnya disarankan untuk menggunakan Type untuk melakukan ini, meskipun mungkin tidak selalu mungkin. Jika menginisialisasi instans kelas ini dengan string, sangat disarankan untuk selalu menggunakan jenis yang sepenuhnya memenuhi syarat, seperti "System.Console" alih-alih hanya "Konsol", karena tidak semua bahasa mendukung impor namespace. Jenis array dapat ditentukan dengan meneruskan objek jenis untuk array atau menggunakan salah satu konstruktor yang menerima peringkat sebagai parameter.

Properti BaseType menentukan nama jenis yang akan dirujuk. Untuk referensi ke jenis array, ArrayElementType properti menunjukkan jenis elemen array, dan ArrayRank properti menunjukkan jumlah dimensi dalam array.

Konstruktor

CodeTypeReference()

Menginisialisasi instans baru kelas CodeTypeReference.

CodeTypeReference(CodeTypeParameter)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan parameter jenis kode yang ditentukan.

CodeTypeReference(CodeTypeReference, Int32)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan jenis dan peringkat array yang ditentukan.

CodeTypeReference(String)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan nama jenis yang ditentukan.

CodeTypeReference(String, CodeTypeReference[])

Menginisialisasi instans CodeTypeReference baru kelas menggunakan nama jenis dan argumen jenis yang ditentukan.

CodeTypeReference(String, CodeTypeReferenceOptions)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan opsi referensi nama jenis dan jenis kode yang ditentukan.

CodeTypeReference(String, Int32)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan nama dan peringkat jenis array yang ditentukan.

CodeTypeReference(Type)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan jenis yang ditentukan.

CodeTypeReference(Type, CodeTypeReferenceOptions)

Menginisialisasi instans CodeTypeReference baru kelas menggunakan jenis dan referensi jenis kode yang ditentukan.

Properti

ArrayElementType

Mendapatkan atau mengatur jenis elemen dalam array.

ArrayRank

Mendapatkan atau mengatur peringkat array array.

BaseType

Mendapatkan atau mengatur nama jenis yang dirujuk.

Options

Mendapatkan atau mengatur opsi referensi jenis kode.

TypeArguments

Mendapatkan argumen jenis untuk referensi jenis generik saat ini.

UserData

Mendapatkan data yang dapat ditetapkan pengguna untuk objek saat ini.

(Diperoleh dari CodeObject)

Metode

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk