Прочетете на английски Редактиране

Споделяне чрез


CodeTypeParameter Constructors

Definition

Initializes a new instance of the CodeTypeParameter class.

Overloads

CodeTypeParameter()

Initializes a new instance of the CodeTypeParameter class.

CodeTypeParameter(String)

Initializes a new instance of the CodeTypeParameter class with the specified type parameter name.

CodeTypeParameter()

Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs

Initializes a new instance of the CodeTypeParameter class.

C#
public CodeTypeParameter();

Remarks

If you use this constructor, you should set the Name property.

Applies to

.NET 10 (package-provided) и други версии
Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

CodeTypeParameter(String)

Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs
Source:
CodeTypeParameter.cs

Initializes a new instance of the CodeTypeParameter class with the specified type parameter name.

C#
public CodeTypeParameter(string name);

Parameters

name
String

The name of the type parameter.

Examples

The following code example shows the use of CodeTypeParameter constructor to add a type parameter. This example is part of a larger example provided for the CodeTypeParameter class.

C#
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);

Applies to

.NET 10 (package-provided) и други версии
Продукт Версии
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10