private static bool IsValid(this PropertyInfo info) { var isValid = info.AccessModifier() == AccessModifier.Public && !ReservedPropertyNames.Contains(info.Name); if (!isValid) { return(false); } if (typeof(IEnumerable).IsAssignableFrom(info.PropertyType)) { return(true); } if (info.PropertyType.IsInterface || info.PropertyType.IsAbstract) { return(false); } return(!(typeof(IEnumerable).IsAssignableFrom(info.PropertyType) && info.PropertyType != typeof(string))); }
private static IEnumerable <PropertyInfo> PublicProperties(this Type type) { return(type.Properties(Flags.AllMembers) .Where(info => { if (info.PropertyType.IsValueType || info.PropertyType == typeof(string)) { return info.CanRead && info.CanWrite; } return true; }) .Where(info => info.AccessModifier() == AccessModifier.Public && !ReservedPropertyNames.Contains(info.Name) && !typeof(ICollection).IsAssignableFrom(info.PropertyType)) .Where(info => { if (info.PropertyType == typeof(string) || info.PropertyType.IsNullableType()) { return true; } return !info.PropertyType.IsGenericType && info.PropertyType != type && info.PropertyType != typeof(object) && ReservedPropertyTypes.Any(_ => info.PropertyType != _); }) .DistinctBy(info => info.Name)); }