internal static FieldOrProperty[] GetFieldsOrProperties(this Type t) { return(fieldOrProperties.WeakMemoize(t, type => new FieldOrProperty[0] .Concat(GetPublicFields(type).Select(p => new FieldOrProperty(p))) .Concat(GetPublicProperties(type).Select(p => new FieldOrProperty(p))) .ToArray() )); }
internal static DictionaryAdapter ToDictionaryOfTypeT(this object that) { Type type = that.GetType(); var dic = dictionaryTypeCtor.WeakMemoize(type, t => typeof(Dictionary <,>) .MakeGenericType(t.GetIDictionaryTypeParameters()) .GetConstructor(new Type[0]) ).Invoke(new object[0]); return(new DictionaryAdapter(that, dic)); }
public static ConstructorInfo GetConstructorWithMostParameters(this Type t) { return(constructorWithMostParameters.WeakMemoize(t, type => { var ctors = type.GetConstructors().ToArray(); if (ctors.Length == 1) { return ctors.First(); } return ctors.Max((ctor1, ctor2) => ParameterLength(ctor1).CompareTo(ParameterLength(ctor2))); })); }
internal static Type[] GetIDictionaryTypeParameters(this Type iDictionaryType) { return(dictionaryTypeParameters.WeakMemoize(iDictionaryType, type => { if (IsExactlyDictionaryType(iDictionaryType)) { return iDictionaryType.GetGenericArguments(); } var t = iDictionaryType.GetInterfaces() .Where(i => IsExactlyDictionaryType(i)) .FirstOrDefault(); return t != null ? t.GetGenericArguments() : new Type[0]; })); }
internal static Type[] GetIEnumerableTypeParameter(this Type iEnumerableType) { return(ienumerableTypeParameters.WeakMemoize(iEnumerableType, type => { if (IsIEnumerableT(iEnumerableType)) { return iEnumerableType.GetGenericArguments(); } return iEnumerableType.GetInterfaces() .Where(i => IsIEnumerableT(i)) .Select(i => i.GetGenericArguments().Single()) .ToArray(); })); }
internal static FieldOrPropertyOrGetMethod[] GetFieldsOrPropertiesOrGetMethods(this Type t, TypeOfFIelds typeOfFIelds) { return(fieldOrPropertyOrMethods.WeakMemoize(t, type => new FieldOrPropertyOrGetMethod[0] .Concat(typeOfFIelds.HasFlag(TypeOfFIelds.Fields) ? GetPublicFields(type).Select(p => new FieldOrPropertyOrGetMethod(p)) : new FieldOrPropertyOrGetMethod[0]) .Concat(typeOfFIelds.HasFlag(TypeOfFIelds.Properties) ? GetPublicProperties(type).Select(p => new FieldOrPropertyOrGetMethod(p)) : new FieldOrPropertyOrGetMethod[0]) .Concat(typeOfFIelds.HasFlag(TypeOfFIelds.Methods) ? GetPublicGetMethods(type).Select(p => new FieldOrPropertyOrGetMethod(p)) : new FieldOrPropertyOrGetMethod[0]) .ToArray() )); }