CodeTypeReference 类

定义

表示对某类型的引用。

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
继承
CodeTypeReference
属性

示例

以下示例演示如何使用 a CodeTypeReference 表示对类型的引用。

// 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)

注解

对象 CodeTypeReference 用于表示 CodeDOM 对象的类型。 当 CodeDOM 类型具有属性 Type 时,它属于类型 CodeTypeReference。 例如,该 CodeMemberField.Type 属性表示 CodeTypeReference 字段的数据类型。

可以使用对象或字符串初始化 Type ACodeTypeReference。 通常建议使用一个 Type 执行此操作,尽管它可能并不总是可能的。 如果使用字符串初始化此类的实例,强烈建议始终使用完全限定的类型,例如“System.Console”,而不是仅使用“控制台”,因为并非所有语言都支持导入命名空间。 可以通过为数组传入类型对象或使用接受排名作为参数的构造函数之一来指定数组类型类型。

BaseType 属性指定要引用的类型的名称。 对于对数组类型的引用,该 ArrayElementType 属性指示数组元素的类型,属性 ArrayRank 指示数组中的维度数。

构造函数

CodeTypeReference()

初始化 CodeTypeReference 类的新实例。

CodeTypeReference(CodeTypeParameter)

使用指定的代码类型参数初始化 CodeTypeReference 类的新实例。

CodeTypeReference(CodeTypeReference, Int32)

使用指定的数组类型和秩初始化 CodeTypeReference 类的新实例。

CodeTypeReference(String)

使用指定的类型名称初始化 CodeTypeReference 类的新实例。

CodeTypeReference(String, CodeTypeReference[])

使用指定的类型名称和类型参数初始化 CodeTypeReference 类的新实例。

CodeTypeReference(String, CodeTypeReferenceOptions)

使用指定的类型名称和代码类型引用选项初始化 CodeTypeReference 类的新实例。

CodeTypeReference(String, Int32)

使用指定的数组类型名称和秩初始化 CodeTypeReference 类的新实例。

CodeTypeReference(Type)

使用指定的类型初始化 CodeTypeReference 类的新实例。

CodeTypeReference(Type, CodeTypeReferenceOptions)

使用指定的类型和代码类型引用初始化 CodeTypeReference 类的新实例。

属性

ArrayElementType

获取或设置数组元素的类型。

ArrayRank

获取或设置数组的数组秩。

BaseType

获取或设置所引用的类型的名称。

Options

获取或设置代码类型引用选项。

TypeArguments

获取当前泛型类型引用的类型参数。

UserData

获取当前对象的用户可定义数据。

(继承自 CodeObject)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于