private static bool FromDateTimeToTypeProxy(DateTime dateTime, object defaultVal, CastingContext context, Type xType, out object result) { if (TypeDeterminer.IsStringType(defaultVal, out var givenFormat)) { return(FromDateTimeToString(dateTime, givenFormat, context, out result)); } if (TypeDeterminer.IsNumericType(xType)) { return(FromDateTimeToNumericType(dateTime, defaultVal, xType, out result)); } if (TypeDeterminer.IsOriginObject(xType)) { result = dateTime; return(true); } result = defaultVal; return(false); }
private static bool FromNumericTypeToTypeProxy <X>(object oVal, X defaultVal, CastingContext context, Type xType, out object result) { if (TypeDeterminer.IsStringType(defaultVal, out var defaultStr)) { return(FromNumericTypeToString(oVal, context, defaultStr, out result)); } if (TypeDeterminer.IsNumericType(xType)) { return(FromNumericTypeToNumericType(oVal, defaultVal, xType, out result)); } if (TypeDeterminer.IsOriginObject(xType)) { result = oVal; return(true); } result = defaultVal; return(false); }
private static bool FromBooleanToTypeProxy(bool oVal, object defaultVal, CastingContext context, Type xType, out object result) { if (TypeDeterminer.IsStringType(xType)) { return(FromBooleanToString(oVal, context, out result)); } if (TypeDeterminer.IsNumericType(xType)) { return(FromBooleanToNumericType(oVal, context, xType, out result)); } if (TypeDeterminer.IsOriginObject(xType)) { result = oVal; return(true); } result = defaultVal; return(false); }
private static bool FromEnumToTypeProxy(Type enumType, object enumVal, object defaultVal, CastingContext context, Type xType, out object result) { if (TypeDeterminer.IsStringType(defaultVal, out var defaultStr)) { return(FromEnumToString(enumType, enumVal, defaultStr, out result)); } if (TypeDeterminer.IsNumericType(xType)) { return(FromEnumToNumericType(enumType, enumVal, defaultVal, xType, out result)); } if (TypeDeterminer.IsOriginObject(xType)) { result = enumVal; return(true); } result = defaultVal; return(false); }
private static bool FromDateTimeToNullableTypeProxy(DateTime dateTime, CastingContext context, Type xType, out object result) { var innerType = TypeConv.GetNonNullableType(xType); if (TypeDeterminer.IsStringType(innerType)) { return(FromDateTimeToNullableString(dateTime, context, out result)); } if (TypeDeterminer.IsNumericType(innerType)) { return(FromDateTimeToNullableNumericType(dateTime, innerType, out result)); } if (TypeDeterminer.IsOriginObject(innerType)) { result = dateTime; return(true); } result = null; return(false); }
private static bool FromNullableNumericTypeToTypeProxy(Type oType, object oVal, CastingContext context, Type xType, out object result) { var innerType = TypeConv.GetNonNullableType(xType); if (TypeDeterminer.IsStringType(innerType)) { return(FromNullableNumericTypeToString(oVal, oType, context, out result)); } if (TypeDeterminer.IsNumericType(innerType)) { return(FromNumericTypeToNullableNumericType(oVal, innerType, out result)); } if (TypeDeterminer.IsOriginObject(innerType)) { result = oVal; return(true); } result = null; return(false); }
private static bool FromObjToNullableTypeProxy(object fromObj, Type xType, out object result) { var innerType = TypeConv.GetNonNullableType(xType); if (TypeDeterminer.IsStringType(innerType)) { result = StrConvX.ObjectSafeToString(fromObj); return(true); } if (TypeDeterminer.IsNumericType(innerType)) { return(FromObjToNullableNumericType(fromObj, innerType, out result)); } if (TypeDeterminer.IsEnumType(innerType)) { result = EnumConvX.ObjToNullableEnum(fromObj, innerType); } if (TypeDeterminer.IsDateTimeTypes(innerType)) { return(FromObjToNullableDateTimeType(fromObj, innerType, out result)); } if (TypeDeterminer.IsGuidType(innerType)) { result = GuidConvX.ObjToNullableGuid(fromObj); return(true); } if (TypeDeterminer.IsOriginObject(innerType)) { result = fromObj; return(true); } result = null; return(false); }
private static bool FromObjToTypeProxy <X>(object fromObj, X defaultVal, Type xType, out object result) { if (TypeDeterminer.IsStringType(defaultVal, out var defaultStr)) { result = StrConvX.ObjectSafeToString(fromObj, defaultStr); return(true); } if (TypeDeterminer.IsNumericType(xType)) { return(FromObjToNumericType(fromObj, defaultVal, xType, out result)); } if (TypeDeterminer.IsEnumType(xType)) { result = EnumConvX.ObjToEnum(fromObj, xType, defaultVal); return(true); } if (TypeDeterminer.IsDateTimeTypes(xType)) { return(FromObjToDateTime(fromObj, defaultVal, xType, out result)); } if (defaultVal is Guid defaultGuid) { result = GuidConvX.ObjToGuid(fromObj, defaultGuid); return(true); } if (TypeDeterminer.IsOriginObject(xType)) { result = defaultVal; return(true); } result = defaultVal; return(false); }