public static bool TryCreate(string dbType, out DecimalMsSqlColumnType returnValue) { returnValue = null; const string numericPrefix = "numeric"; const string decimalPrefix = "decimal"; string arguments; if (dbType.StartsWith(numericPrefix)) { arguments = dbType .Substring(numericPrefix.Length, dbType.Length - numericPrefix.Length) .Trim(); } else if (dbType.StartsWith(decimalPrefix)) { arguments = dbType .Substring(numericPrefix.Length, dbType.Length - numericPrefix.Length) .Trim(); } else { return(false); } if (!string.IsNullOrEmpty(arguments)) { if (!(arguments[0] == '(' && arguments[arguments.Length - 1] == ')')) { throw new InvalidOperationException($"Invalid arguments for decimal MS SQL type: {dbType}"); } var splitArguments = arguments.Substring(1, arguments.Length - 2).Split(','); if (splitArguments.Length == 1 && int.TryParse(splitArguments[0], out var precision)) { returnValue = new DecimalMsSqlColumnType(precision, 0); } else if (splitArguments.Length == 2 && int.TryParse(splitArguments[0], out precision) && int.TryParse(splitArguments[1], out var scale)) { returnValue = new DecimalMsSqlColumnType(precision, scale); } else { throw new InvalidOperationException($"Invalid arguments for decimal MS SQL type: {dbType}"); } } else { returnValue = new DecimalMsSqlColumnType(18, 0); } return(true); }
public static MsSqlColumnType Create(string databaseType) { var dbType = databaseType.ToLowerInvariant(); if (IntegerMsSqlColumnType.TryCreate(dbType, out var integerType)) { return(integerType); } if (FloatingPointMsSqlColumnType.TryCreate(dbType, out var floatingType)) { return(floatingType); } if (DecimalMsSqlColumnType.TryCreate(dbType, out var decimalType)) { return(decimalType); } if (DateTimeMsSqlColumnType.TryCreate(dbType, out var dateTimeType)) { return(dateTimeType); } if (VarCharMsSqlColumnType.TryCreate(dbType, out var varcharType)) { return(varcharType); } if (TextMsSqlColumnType.TryCreate(dbType, out var textType)) { return(textType); } throw new NotImplementedException($"The database type \'{dbType}\' is not yet supported"); }