/// <summary> /// Gets the supplied Source string converted to a value with the most well suited basic data-type. /// Optionally, an indication of consider empty-string as null can be specified. /// </summary> public static Tuple <object, BasicDataType> ConvertToMostSuitedBasicDataType(string Source, bool EmptyIsNull = false) { object Value = null; // Do not assign Value here, it is overwritten by the "TryParses outs" even when not returning a value BasicDataType Kind = null; // POSTPONED: Add more specific types (also improve TryParseValueFrom() methods) if (Source.IsAbsent()) { Kind = DataType.DataTypeText; if (EmptyIsNull) { Value = null; } } else if (DataTypeNumber.TryParseValueFrom(Source, out Value)) { Kind = DataTypeNumber; } else if (DataTypeDateTime.TryParseValueFrom(Source, out Value)) { Kind = DataTypeDateTime; } else { Value = Source; Kind = DataType.DataTypeText; } return(Tuple.Create(Value, Kind)); }
/// <summary> /// Returns the wider basic data-type of this Original respect the Alternative. /// </summary> public static BasicDataType GetWiderBasicDataTypeRespect(BasicDataType Original, BasicDataType Alternative) { // POSTPONED: Extend being more specific. if (Original == Alternative) { return(Original); } return(DataType.DataTypeText); }