Breyta

Deila með


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

Initializes a new instance of the CodeTypeParameter class.

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

Remarks

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

Applies to

CodeTypeParameter(String)

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.

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

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.

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)

Applies to