コード例 #1
0
ファイル: SqlType.cs プロジェクト: meikeric/deveeldb
        /// <summary>
        /// Parses a SQL formatted string that defines a data-type into
        /// a constructed <see cref="SqlType"/> object equivalent.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="s">The SQL formatted data-type string, defining the properties of the type.</param>
        /// <remarks>
        /// This method only supports primitive types.
        /// </remarks>
        /// <returns>
        /// </returns>
        /// <seealso cref="PrimitiveTypes.IsPrimitive(Deveel.Data.Types.SqlTypeCode)"/>
        /// <seealso cref="ToString()"/>
        public static SqlType Parse(IContext context, string s)
        {
            var sqlCompiler = SqlParsers.DataType;

            try {
                var result = sqlCompiler.Parse(s);
                if (result.HasErrors)
                {
                    throw new SqlParseException(result.Errors.First().Message);
                }

                var node = (DataTypeNode)result.RootNode;

                if (context == null && !node.IsPrimitive)
                {
                    throw new NotSupportedException(String.Format("The type '{0}' is not primitive and no resolve context is provided.", node.TypeName));
                }

                return(DataTypeBuilder.Build(context.TypeResolver(), node));
            } catch (SqlParseException) {
                throw new FormatException("Unable to parse the given string to a valid data type.");
            }
        }
コード例 #2
0
    public void Can_Serialize_Without_Error()
    {
        var item = _builder.Build();

        Assert.DoesNotThrow(() => JsonConvert.SerializeObject(item));
    }