public static ConstructorInfoEx GetConstructorEx(ConstructorInfo constructorInfo) { if (!cache.TryGetValue(constructorInfo, out var prop)) { prop = new ConstructorInfoEx(constructorInfo); cache.TryAdd(constructorInfo, prop); } return(prop); }
private EnumerableTypeDescriptor(Type type) { Type = type; if (type == typeof(string)) { EnumerableInterfaces = new List <EnumerableInterfaceDescriptor>(); } else if (type.IsArray) { EnumerableInterfaces = new List <EnumerableInterfaceDescriptor>() { EnumerableInterfaceDescriptor.GetArray(type) } } ; else { EnumerableInterfaces = new ReadOnlyCollection <EnumerableInterfaceDescriptor>( Type.GetInterfaces() .Join(SupportedEnumerableTypes.Types, x => x.GetTypeOrGenericTypeDefinition(), y => y.Key.GetTypeOrGenericTypeDefinition(), (x, y) => new EnumerableInterfaceDescriptor(x, y.Value)) .GroupBy(x => x.GenericArgumentHashCode) .Select(x => x.Aggregate((accumulate, current) => current.Type.IsSuperclassOf(accumulate.Type) ? current : accumulate)) .ToList()); } IsEnumerable = EnumerableInterfaces.Any(); if (!IsEnumerable) { return; } if (Type.IsArray) { ExplicitImplementation = EnumerableInterfaces.Single(); } else { var defaultEnumeratorElementType = GetExplicitEnumerableElementType(Type); if (defaultEnumeratorElementType != null) { ExplicitImplementation = EnumerableInterfaces.FirstOrDefault(x => x.ElementType == defaultEnumeratorElementType); } } if (!Type.ContainsGenericParameters && !Type.IsAbstract) { parameterlessConstructor = DiscoverParameterlessConstructor(); constructorsWithEnumerableParameter = DiscoverConstructors(); } if (!Type.ContainsGenericParameters) { listMethods = DiscoverListMethods(); dictionaryMethods = DiscoverDictionaryMethods(); } }