CodeTypeParameter 建構函式

定義

初始化 CodeTypeParameter 類別的新執行個體。

多載

CodeTypeParameter()

初始化 CodeTypeParameter 類別的新執行個體。

CodeTypeParameter(String)

使用指定的型別參數名稱,初始化 CodeTypeParameter 類別的新執行個體。

CodeTypeParameter()

來源:
CodeTypeParameter.cs
來源:
CodeTypeParameter.cs
來源:
CodeTypeParameter.cs

初始化 CodeTypeParameter 類別的新執行個體。

public:
 CodeTypeParameter();
public CodeTypeParameter ();
Public Sub New ()

備註

如果您使用這個建構函式,您應該設定 Name 屬性。

適用於

CodeTypeParameter(String)

來源:
CodeTypeParameter.cs
來源:
CodeTypeParameter.cs
來源:
CodeTypeParameter.cs

使用指定的型別參數名稱,初始化 CodeTypeParameter 類別的新執行個體。

public:
 CodeTypeParameter(System::String ^ name);
public CodeTypeParameter (string name);
new System.CodeDom.CodeTypeParameter : string -> System.CodeDom.CodeTypeParameter
Public Sub New (name As String)

參數

name
String

型別參數的名稱。

範例

下列程式代碼範例示範如何使用 CodeTypeParameter 建構函式來新增類型參數。 此範例是針對 類別提供的較大範例的 CodeTypeParameter 一部分。

CodeTypeParameter kType = new CodeTypeParameter("TKey");
kType.HasConstructorConstraint = true;
kType.Constraints.Add(new CodeTypeReference(typeof(IComparable)));
kType.CustomAttributes.Add(new CodeAttributeDeclaration(
    "System.ComponentModel.DescriptionAttribute",
        new CodeAttributeArgument(new CodePrimitiveExpression("KeyType"))));

CodeTypeReference iComparableT = new CodeTypeReference("IComparable");
iComparableT.TypeArguments.Add(new CodeTypeReference(kType));

kType.Constraints.Add(iComparableT);

CodeTypeParameter vType = new CodeTypeParameter("TValue");
vType.Constraints.Add(new CodeTypeReference(typeof(IList<System.String>)));
vType.CustomAttributes.Add(new CodeAttributeDeclaration(
    "System.ComponentModel.DescriptionAttribute",
        new CodeAttributeArgument(new CodePrimitiveExpression("ValueType"))));

class1.TypeParameters.Add(kType);
class1.TypeParameters.Add(vType);
Dim kType As New CodeTypeParameter("TKey")
kType.HasConstructorConstraint = True
kType.Constraints.Add(New CodeTypeReference(GetType(IComparable)))
kType.CustomAttributes.Add _
    (New CodeAttributeDeclaration("System.ComponentModel.DescriptionAttribute", _
        New CodeAttributeArgument(New CodePrimitiveExpression("KeyType"))))
Dim iComparableT As New CodeTypeReference("IComparable")
iComparableT.TypeArguments.Add(New CodeTypeReference(kType))

kType.Constraints.Add(iComparableT)

Dim vType As New CodeTypeParameter("TValue")
vType.Constraints.Add(New CodeTypeReference(GetType(IList(Of System.String))))
vType.CustomAttributes.Add _
    (New CodeAttributeDeclaration("System.ComponentModel.DescriptionAttribute", _
        New CodeAttributeArgument(New CodePrimitiveExpression("ValueType"))))

class1.TypeParameters.Add(kType)
class1.TypeParameters.Add(vType)

適用於