System.Type.GetGenericArguments C# (CSharp) Method

GetGenericArguments() public method

Returns an array of T:System.Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.
The invoked method is not supported in the base class. Derived classes must provide an implementation.
public GetGenericArguments ( ) : Type[]
return Type[]
        public virtual Type[] GetGenericArguments()
        {
            return GenericTypeArguments;
        }

Usage Example

Ejemplo n.º 1
7
        public static IType InferType(Type type, IMetadataContainer container)
        {
            Type genericTypeDefinition = type.GetGenericArguments().Any() ? type.GetGenericTypeDefinition() : type;

            if (typeof(IFunction<,>).IsAssignableFrom(genericTypeDefinition))
            {
                Type left = type.GetGenericArguments()[0];
                Type right = type.GetGenericArguments()[1];
                return new Types.ArrowType(InferType(left, container), InferType(right, container));
            }
            else if (typeof(Either<,>).IsAssignableFrom(genericTypeDefinition))
            {
                Type left = type.GetGenericArguments()[0];
                Type right = type.GetGenericArguments()[1];
                return new Types.SumType(InferType(left, container), InferType(right, container));
            }
            else if (typeof(Tuple<,>).IsAssignableFrom(genericTypeDefinition))
            {
                Type left = type.GetGenericArguments()[0];
                Type right = type.GetGenericArguments()[1];
                return new Types.ProductType(InferType(left, container), InferType(right, container));
            }
            else if (type.IsGenericParameter)
            {
                return new Types.TypeParameter(type.Name);
            }
            else
            {
                container.ResolveType(type.Name);
                var genericParameters = type.GetGenericArguments().Select(t => InferType(t, container)).ToArray();
                return new Types.TypeSynonym(type.Name, genericParameters);
            }
        }
All Usage Examples Of System.Type::GetGenericArguments