Forum Discussion

ahinterl's avatar
ahinterl
Brass Contributor
Feb 11, 2025
Solved

How to find out the type of a generic class?

Exmple: create a new List<string> instance: $a = [System.Collections.Generic.List[string]]::new() With: $a.GetType() I only get: IsPublic IsSerial Name                                     Ba...
  • ahinterl's avatar
    Feb 11, 2025
    ($a.GetType()).GetType()

    Returns:

    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    False    False    RuntimeType                              System.Reflection.TypeInfo

    TypeInfo derives from System.Type, which has this method:

    $a.GetType().GetGenericArguments()[0]

    which returns the same as in my previous post:

    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     String                                   System.Object

     

Resources