Пример #1
0
 private static bool IsCompatibleObject(object value)
 {
     return(value is T || value == null && (!TypeExtensions.IsValueType(typeof(T)) || ReflectionUtils.IsNullableType(typeof(T))));
 }
Пример #2
0
        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));
        }
Пример #3
0
 public static bool IsNullableType(Type t)
 {
     ValidationUtils.ArgumentNotNull(t, "t");
     return(TypeExtensions.IsGenericType(t) && t.GetGenericTypeDefinition() == typeof(Nullable <>));
 }
Пример #4
0
 public static bool IsNullable(Type t)
 {
     ValidationUtils.ArgumentNotNull(t, "t");
     return(!TypeExtensions.IsValueType(t) || IsNullableType(t));
 }
Пример #5
0
 public static bool HasDefaultConstructor(Type t, bool nonPublic)
 {
     ValidationUtils.ArgumentNotNull(t, "t");
     return(TypeExtensions.IsValueType(t) || GetDefaultConstructor(t, nonPublic) != null);
 }
Пример #6
0
 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)));
 }