public static IType GetItemType(this IType source)
        {
            if (!source.CanBeCollection())
            {
                throw new ArgumentException("Type should be a generic collection or an array to have an item type", nameof(source));
            }
            if (source.IsGenericType)
            {
                return(source.GetGenericArguments()[0]);
            }
            if (source.IsArray)
            {
                return(source.GetElementType());
            }

            throw new NotSupportedException();
        }
Пример #2
0
 private static IType Fix(IType type) => type.CanBeCollection() ? type.GetItemType() : type;
 public static bool CanBeCollection <T>(this IType source) => source.CanBeCollection(type.of <T>());
 public static bool CanBeCollection(this IType source) => source.CanBeCollection <object>();