private IEnumerable <MemberInfo> GetAllPublicMembers( Func <PropertyInfo, bool> propertyAvailableFor, Func <FieldInfo, bool> fieldAvailableFor, Func <MemberInfo, bool> memberAvailableFor) { var typesToScan = new List <Type>(); for (var t = Type; t != null; t = TypeExtensions.BaseType(t)) { typesToScan.Add(t); } if (TypeExtensions.IsInterface(Type)) { typesToScan.AddRange(Type.GetInterfaces()); } // Scan all types for public properties and fields return(typesToScan .Where(x => x != null) // filter out null types (e.g. type.BaseType == null) .SelectMany(x => TypeExtensions.GetDeclaredMembers(x) .Where(mi => mi.DeclaringType != null && mi.DeclaringType == x) .Where( m => (m is FieldInfo && fieldAvailableFor((FieldInfo)m)) || (m is PropertyInfo && propertyAvailableFor((PropertyInfo)m) && !((PropertyInfo)m).GetIndexParameters().Any())) .Where(memberAvailableFor) )); }
private static Type GetIEnumerableType(Type enumerableType) { try { return(enumerableType.GetInterfaces().FirstOrDefault(t => t.Name == "IEnumerable`1")); } catch (AmbiguousMatchException) { if (TypeExtensions.BaseType(enumerableType) != typeof(object)) { return(GetIEnumerableType(TypeExtensions.BaseType(enumerableType))); } return(null); } }
private IEnumerable <Type> GetAllTypes(Type type) { yield return(type); var baseType = TypeExtensions.BaseType(type); while (baseType != null) { yield return(baseType); baseType = TypeExtensions.BaseType(baseType); } foreach (var interfaceType in type.GetInterfaces()) { yield return(interfaceType); } }