/// <summary> 构造用于拓展系统Type对象的属性和方法的对象 /// </summary> /// <param name="type">用于构造TypeInfo的Type对象实例,不可为null</param> internal TypeInfo(System.Type type) { if (type == null) { throw new ArgumentNullException("type"); } Type = type; TypeCode = System.Type.GetTypeCode(type); IsArray = type.IsArray; IsMakeGenericType = type.IsGenericType && !type.IsGenericTypeDefinition; var valueType = Nullable.GetUnderlyingType(type); if (valueType != null) //判断可空值类型 { IsNullable = true; NullableUnderlyingType = TypesHelper.GetTypeInfo(valueType); type = valueType; } if (type.IsEnum) { IsNumberType = true; EnumUnderlyingType = TypesHelper.GetTypeInfo(Enum.GetUnderlyingType(Type)); } else if (IsNullable) { IsNumberType = NullableUnderlyingType.IsNumberType; } else { IsNumberType = (TypeCode >= TypeCode.SByte && TypeCode <= TypeCode.Decimal); } }
/// <summary> 获取缓存 /// </summary> /// <param name="type">反射对象类型</param> /// <param name="ignoreCase">属性/字段名称是否忽略大小写</param> /// <exception cref="ArgumentException">缓存中的对象类型与参数type不一致</exception> /// <exception cref="ArgumentNullException">参数type为null</exception> public static Literacy Cache(Type type, bool ignoreCase) { if (type == null) { throw new ArgumentNullException("type"); } var info = TypesHelper.GetTypeInfo(type); return(ignoreCase ? info.IgnoreCaseLiteracy : info.Literacy); }
/// <summary> 初始化 /// </summary> private void Init() { Name = MemberInfo.Name; ClassType = MemberInfo.DeclaringType; TypeInfo = TypesHelper.GetTypeInfo(OriginalType); if (TypeInfo.IsNullable) { Nullable = true; MemberType = TypeInfo.NullableUnderlyingType.Type; } else { MemberType = OriginalType; } Getter = PreGetter; Setter = PreSetter; }
/// <summary> 初始化对象属性,字段访问组件,ignoreCase参数指示是否需要区分大小写 /// </summary> /// <param name="type">需快速访问的类型</param> /// <param name="ignoreCase">是否区分大小写(不区分大小写时应保证类中没有同名的(仅大小写不同的)属性或字段)</param> public Literacy(Type type, bool ignoreCase) : this(TypesHelper.GetTypeInfo(type), ignoreCase) { }