src/Mimp.SeeSharper.Reflection/TypeExtensions.Generic.cs
/// <summary>
/// Return all generic arguments of <paramref name="genericTypeDefinition"/>.
/// </summary>
/// <param name="type"></param>
/// <param name="genericTypeDefinition"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="ArgumentException">If <paramref name="genericTypeDefinition"/> isn't a generic type definition.</exception>
Return all generic arguments of .
Return all generic arguments of .
public static IEnumerable<IEnumerable<Type>> GetAllGenericArguments(this Type type, Type genericTypeDefinition)
        {
            if (type is null)
                throw new ArgumentNullException(nameof(type));
            if (genericTypeDefinition is null)
                throw new ArgumentNullException(nameof(genericTypeDefinition));
            if (!genericTypeDefinition.IsGenericTypeDefinition)
                throw new ArgumentException($"{genericTypeDefinition} isn't a generic type definition.", nameof(genericTypeDefinition));
            static bool TryGet(Type type, Type genericTypeDefinition, out Type[]? types)
            {
                if (type == genericTypeDefinition)
                {
                    types = Type.EmptyTypes;
                    return true;
                }
                if (genericTypeDefinition.IsGenericTypeDefinition &&
                    type.IsGenericType && type.GetGenericTypeDefinition() == genericTypeDefinition)
                {
                    types = type.GetGenericArguments();
                    return true;
                }
                types = null;
                return false;
            }
            if (TryGet(type, genericTypeDefinition, out var types))
                yield return types!;
            foreach (var i in type.GetInheritTypes())
                if (TryGet(i, genericTypeDefinition, out types))
                    yield return types!;
        }
public static IEnumerable < IEnumerable < Type > > GetAllGenericArguments ( this Type type , Type genericTypeDefinition ) { if ( type is null ) throw new ArgumentNullException ( nameof ( type ) ) ; if ( genericTypeDefinition is null ) throw new ArgumentNullException ( nameof ( genericTypeDefinition ) ) ; if ( ! genericTypeDefinition . IsGenericTypeDefinition ) throw new ArgumentException ( $" { genericTypeDefinition }  isn't a generic type definition. " , nameof ( genericTypeDefinition ) ) ; static bool TryGet ( Type type , Type genericTypeDefinition , out Type [ ] ? types ) { if ( type == genericTypeDefinition ) { types = Type . EmptyTypes ; return true ; } if ( genericTypeDefinition . IsGenericTypeDefinition && type . IsGenericType && type . GetGenericTypeDefinition ( ) == genericTypeDefinition ) { types = type . GetGenericArguments ( ) ; return true ; } types = null ; return false ; } if ( TryGet ( type , genericTypeDefinition , out var types ) ) yield return types ! ; foreach ( var i in type . GetInheritTypes ( ) ) if ( TryGet ( i , genericTypeDefinition , out types ) ) yield return types ! ; }
Return all generic arguments of .
Return all generic arguments of .
None
None
If  isn't a generic type definition.
If isn ' t a generic type definition .
Type
this
genericTypeDefinition
Type
None
type
None