public SqlType Parse(IContext context, string s) { var parser = new SqlParser(); var typeInfo = parser.ParseType(s); if (PrimitiveTypes.IsPrimitive(typeInfo.TypeName)) { return(PrimitiveTypes.Resolver.Resolve(typeInfo)); } if (context == null) { throw new Exception($"Type {typeInfo.TypeName} is not primitive and no context is provided"); } var resolver = context.Scope.Resolve <ISqlTypeResolver>(); if (resolver == null) { throw new InvalidOperationException($"The type {typeInfo.TypeName} is not primitive and no resolver was found in context"); } return(resolver.Resolve(typeInfo)); }
public static void IsPrimitive(SqlTypeCode typeCode, bool expected) { Assert.Equal(expected, PrimitiveTypes.IsPrimitive(typeCode)); }
///// <summary> ///// Gets the SQL type code corresponding to the given type ///// </summary> ///// <param name="type">The type to get the corresponding type code</param> ///// <returns> ///// Returns a <see cref="SqlTypeCode"/> that represents a code corresponding ///// the SQL type. ///// </returns> ///// <exception cref="NotSupportedException">If the given <paramref name="type"/> ///// is not supported by the system</exception> //public static SqlTypeCode GetTypeCode(Type type) { // if (type == null) // return SqlTypeCode.Unknown; // if (type == typeof(bool)) // return SqlTypeCode.Boolean; // if (type == typeof(byte)) // return SqlTypeCode.TinyInt; // if (type == typeof(short)) // return SqlTypeCode.SmallInt; // if (type == typeof(int)) // return SqlTypeCode.Integer; // if (type == typeof(long)) // return SqlTypeCode.BigInt; // if (type == typeof(float)) // return SqlTypeCode.Real; // if (type == typeof(double)) // return SqlTypeCode.Double; // if (type == typeof(DateTime) || // type == typeof(DateTimeOffset)) // return SqlTypeCode.TimeStamp; // if (type == typeof(TimeSpan)) // return SqlTypeCode.DayToSecond; // if (type == typeof(string)) // return SqlTypeCode.String; // if (type == typeof(byte[])) // return SqlTypeCode.Binary; // if (type == typeof(SqlBoolean)) // return SqlTypeCode.Boolean; // if (type == typeof(SqlNumber)) // return SqlTypeCode.Numeric; // if (type == typeof(SqlDateTime)) // return SqlTypeCode.TimeStamp; // if (type == typeof(SqlString)) // return SqlTypeCode.String; // if (type == typeof(SqlDayToSecond)) // return SqlTypeCode.DayToSecond; // throw new NotSupportedException(String.Format("The type '{0}' is not supported.", type)); //} public static bool IsPrimitiveType(SqlTypeCode typeCode) { return(PrimitiveTypes.IsPrimitive(typeCode)); }
public static void IsPrimitive(string name, bool expected) { Assert.Equal(expected, PrimitiveTypes.IsPrimitive(name)); }