Type.IsGenericParameter Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Beolvas egy értéket, amely jelzi, hogy az aktuális Type érték egy típusparamétert jelöl-e egy általános típus vagy metódus definíciójában.
public:
abstract property bool IsGenericParameter { bool get(); };
public:
virtual property bool IsGenericParameter { bool get(); };
public abstract bool IsGenericParameter { get; }
public virtual bool IsGenericParameter { get; }
member this.IsGenericParameter : bool
Public MustOverride ReadOnly Property IsGenericParameter As Boolean
Public Overridable ReadOnly Property IsGenericParameter As Boolean
Tulajdonság értéke
trueha az Type objektum egy általános típusdefiníció vagy általános metódusdefiníció típusparaméterét jelöli; ellenkező esetben. false
Példák
Az alábbi példa a tulajdonság használatával teszteli az IsGenericParameter általános típus paramétereit egy általános típusban.
if (t.IsGenericType)
{
// If this is a generic type, display the type arguments.
//
Type[] typeArguments = t.GetGenericArguments();
Console.WriteLine("\tList type arguments ({0}):",
typeArguments.Length);
foreach (Type tParam in typeArguments)
{
// If this is a type parameter, display its
// position.
//
if (tParam.IsGenericParameter)
{
Console.WriteLine("\t\t{0}\t(unassigned - parameter position {1})",
tParam,
tParam.GenericParameterPosition);
}
else
{
Console.WriteLine("\t\t{0}", tParam);
}
}
}
if t.IsGenericType then
// If this is a generic type, display the type arguments.
let typeArguments = t.GetGenericArguments()
printfn $"\tList type arguments ({typeArguments.Length}):"
for tParam in typeArguments do
// If this is a type parameter, display its position.
if tParam.IsGenericParameter then
printfn $"\t\t{tParam}\t(unassigned - parameter position {tParam.GenericParameterPosition})"
else
printfn $"\t\t{tParam}"
If t.IsGenericType Then
' If this is a generic type, display the type arguments.
'
Dim typeArguments As Type() = t.GetGenericArguments()
Console.WriteLine(vbTab & "List type arguments (" _
& typeArguments.Length & "):")
For Each tParam As Type In typeArguments
' If this is a type parameter, display its position.
'
If tParam.IsGenericParameter Then
Console.WriteLine(vbTab & vbTab & tParam.ToString() _
& vbTab & "(unassigned - parameter position " _
& tParam.GenericParameterPosition & ")")
Else
Console.WriteLine(vbTab & vbTab & tParam.ToString())
End If
Next tParam
End If
Megjegyzések
TypeAz általános típusparamétereket képviselő objektumok egy általános típusdefiníciót képviselő objektum metódusának GetGenericArguments meghívásával, vagy egy Type általános metódusdefiníciót képviselő objektum metódusának GetGenericArguments meghívásával MethodInfo kérhetők le.
Általános típus- vagy metódusdefiníció esetén a tulajdonság az IsGenericParameter eredményül kapott tömb minden elemére érvényes
true.Zárt építésű típus vagy metódus esetén a tulajdonság a IsGenericParameter metódus által
falsevisszaadott tömb minden elemére visszatérGetGenericArguments.Nyitott, konstruktált típus vagy metódus esetén a tömb egyes elemei adott típusok lehetnek, mások pedig típusparaméterek. IsGenericParameter visszaadja
falsea típusokat éstruea típusparamétereket. A tulajdonság kód példája egy ContainsGenericParameters általános osztályt mutat be típusok és típusparaméterek keverékével.
Az általános tükrözésben használt kifejezések invariáns feltételeinek listáját a IsGenericType tulajdonság megjegyzéseiben találja.