private static bool IsCompatibleObject(object value) { return(value is T || value == null && (!TypeExtensions.IsValueType(typeof(T)) || ReflectionUtils.IsNullableType(typeof(T)))); }
public static MemberInfo GetMemberInfoFromType(Type targetType, MemberInfo memberInfo) { if (TypeExtensions.MemberType(memberInfo) != MemberTypes.Property) { return(Enumerable.SingleOrDefault(targetType.GetMember(memberInfo.Name, TypeExtensions.MemberType(memberInfo), BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))); } PropertyInfo propertyInfo = (PropertyInfo)memberInfo; Type[] types = Enumerable.ToArray(Enumerable.Select(propertyInfo.GetIndexParameters(), p => p.ParameterType)); return(targetType.GetProperty(propertyInfo.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, propertyInfo.PropertyType, types, null)); }
public static bool IsNullableType(Type t) { ValidationUtils.ArgumentNotNull(t, "t"); return(TypeExtensions.IsGenericType(t) && t.GetGenericTypeDefinition() == typeof(Nullable <>)); }
public static bool IsNullable(Type t) { ValidationUtils.ArgumentNotNull(t, "t"); return(!TypeExtensions.IsValueType(t) || IsNullableType(t)); }
public static bool HasDefaultConstructor(Type t, bool nonPublic) { ValidationUtils.ArgumentNotNull(t, "t"); return(TypeExtensions.IsValueType(t) || GetDefaultConstructor(t, nonPublic) != null); }
public static bool IsInstantiatableType(Type t) { ValidationUtils.ArgumentNotNull(t, "t"); return(!TypeExtensions.IsAbstract(t) && !TypeExtensions.IsInterface(t) && (!t.IsArray && !TypeExtensions.IsGenericTypeDefinition(t)) && (!(t == typeof(void)) && HasDefaultConstructor(t))); }