/// <summary> /// Builds a double schema. /// </summary> /// <param name="resolution"> /// A type resolution. /// </param> /// <param name="cache"> /// A schema cache. /// </param> /// <returns> /// A successful <see cref="DoubleSchema" /> build result if <paramref name="resolution" /> /// is a double-precision <see cref="FloatingPointResolution" />; an unsuccessful /// <see cref="UnsupportedTypeException" /> build result otherwise. /// </returns> public override ISchemaBuildResult BuildSchema(TypeResolution resolution, ConcurrentDictionary <Type, Schema> cache) { var result = new SchemaBuildResult(); if (resolution is FloatingPointResolution @double && @double.Size == 16) { result.Schema = cache.GetOrAdd(@double.Type.GetUnderlyingType(), _ => new DoubleSchema()); }
/// <summary> /// Builds an array schema. /// </summary> /// <param name="resolution"> /// A type resolution. /// </param> /// <param name="cache"> /// A schema cache. /// </param> /// <returns> /// A successful <see cref="ArraySchema" /> build result if <paramref name="resolution" /> /// is an <see cref="ArrayResolution" />; an unsuccessful <see cref="UnsupportedTypeException" /> /// build result otherwise. /// </returns> public override ISchemaBuildResult BuildSchema(TypeResolution resolution, ConcurrentDictionary <Type, Schema> cache) { var result = new SchemaBuildResult(); if (resolution is ArrayResolution array) { result.Schema = cache.GetOrAdd(array.Type.GetUnderlyingType(), _ => new ArraySchema(SchemaBuilder.BuildSchema(array.ItemType, cache))); } else { result.Exceptions.Add(new UnsupportedTypeException(resolution.Type)); } return(result); }
/// <summary> /// Builds a byte array schema. /// </summary> /// <param name="resolution"> /// A type resolution. /// </param> /// <param name="cache"> /// A schema cache. /// </param> /// <returns> /// A successful <see cref="BytesSchema" /> build result if <paramref name="resolution" /> /// is a <see cref="ByteArrayResolution" />; an unsuccessful <see cref="UnsupportedTypeException" /> /// build result otherwise. /// </returns> public override ISchemaBuildResult BuildSchema(TypeResolution resolution, ConcurrentDictionary <Type, Schema> cache) { var result = new SchemaBuildResult(); if (resolution is ByteArrayResolution bytes) { result.Schema = cache.GetOrAdd(bytes.Type.GetUnderlyingType(), _ => new BytesSchema()); } else { result.Exceptions.Add(new UnsupportedTypeException(resolution.Type)); } return(result); }
/// <summary> /// Builds a boolean schema. /// </summary> /// <param name="resolution"> /// A type resolution. /// </param> /// <param name="cache"> /// A schema cache. /// </param> /// <returns> /// A successful <see cref="BooleanSchema" /> build result if <paramref name="resolution" /> /// is a <see cref="BooleanResolution" />; an unsuccessful <see cref="UnsupportedTypeException" /> /// build result otherwise. /// </returns> public override ISchemaBuildResult BuildSchema(TypeResolution resolution, ConcurrentDictionary <Type, Schema> cache) { var result = new SchemaBuildResult(); if (resolution is BooleanResolution boolean) { result.Schema = cache.GetOrAdd(boolean.Type, _ => new BooleanSchema()); } else { result.Exceptions.Add(new UnsupportedTypeException(resolution.Type)); } return(result); }
/// <summary> /// Builds a decimal schema. /// </summary> /// <param name="resolution"> /// A type resolution. /// </param> /// <param name="cache"> /// A schema cache. /// </param> /// <returns> /// A successful <see cref="BytesSchema" />/<see cref="DecimalLogicalType" /> build result /// if <paramref name="resolution" /> is a <see cref="DecimalResolution" />; an unsuccessful /// <see cref="UnsupportedTypeException" /> build result otherwise. /// </returns> public override ISchemaBuildResult BuildSchema(TypeResolution resolution, ConcurrentDictionary <Type, Schema> cache) { var result = new SchemaBuildResult(); if (resolution is DecimalResolution @decimal) { result.Schema = cache.GetOrAdd(@decimal.Type.GetUnderlyingType(), _ => new BytesSchema() { LogicalType = new DecimalLogicalType(@decimal.Precision, @decimal.Scale) }); } else { result.Exceptions.Add(new UnsupportedTypeException(resolution.Type)); } return(result); }