CodeTypeParameter 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 CodeTypeParameter 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| CodeTypeParameter() |
初始化 CodeTypeParameter 類別的新執行個體。 |
| CodeTypeParameter(String) |
初始化一個以指定型別參數名稱的類別新 CodeTypeParameter 實例。 |
CodeTypeParameter()
初始化 CodeTypeParameter 類別的新執行個體。
public:
CodeTypeParameter();
public CodeTypeParameter();
Public Sub New ()
備註
如果你使用這個建構子,應該設定屬性 Name 。
適用於
CodeTypeParameter(String)
初始化一個以指定型別參數名稱的類別新 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)