|
| 1 | + |
| 2 | +using System; |
| 3 | + |
| 4 | +using System.Threading; |
| 5 | + |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +using Npgsql.Internal; |
| 9 | + |
| 10 | +using System.Collections.Concurrent; |
| 11 | + |
| 12 | +using System.Collections.ObjectModel; |
| 13 | + |
| 14 | +using GeoJSON.Net; |
| 15 | + |
| 16 | +using GeoJSON.Net.CoordinateReferenceSystem; |
| 17 | + |
| 18 | +using GeoJSON.Net.Geometry; |
| 19 | + |
| 20 | +using Npgsql.BackendMessages; |
| 21 | + |
| 22 | +using Npgsql.Internal.TypeHandling; |
| 23 | + |
| 24 | +using Npgsql.PostgresTypes; |
| 25 | + |
| 26 | + |
| 27 | +#nullable enable |
| 28 | +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member |
| 29 | +#pragma warning disable RS0016 // Add public types and members to the declared API |
| 30 | +#pragma warning disable 618 // Member is obsolete |
| 31 | + |
| 32 | +namespace Npgsql.GeoJSON.Internal |
| 33 | +{ |
| 34 | + partial class GeoJsonHandler |
| 35 | + { |
| 36 | + public override int ValidateObjectAndGetLength(object value, ref NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter) |
| 37 | + => value switch |
| 38 | + { |
| 39 | + |
| 40 | + Point converted => ((INpgsqlTypeHandler<Point>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 41 | + |
| 42 | + MultiPoint converted => ((INpgsqlTypeHandler<MultiPoint>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 43 | + |
| 44 | + Polygon converted => ((INpgsqlTypeHandler<Polygon>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 45 | + |
| 46 | + MultiPolygon converted => ((INpgsqlTypeHandler<MultiPolygon>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 47 | + |
| 48 | + LineString converted => ((INpgsqlTypeHandler<LineString>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 49 | + |
| 50 | + MultiLineString converted => ((INpgsqlTypeHandler<MultiLineString>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 51 | + |
| 52 | + GeometryCollection converted => ((INpgsqlTypeHandler<GeometryCollection>)this).ValidateAndGetLength(converted, ref lengthCache, parameter), |
| 53 | + |
| 54 | + |
| 55 | + _ => throw new InvalidCastException($"Can't write CLR type {value.GetType()} with handler type GeoJsonHandler") |
| 56 | + }; |
| 57 | + |
| 58 | + public override Task WriteObjectWithLength(object? value, NpgsqlWriteBuffer buf, NpgsqlLengthCache? lengthCache, NpgsqlParameter? parameter, bool async, CancellationToken cancellationToken = default) |
| 59 | + => value switch |
| 60 | + { |
| 61 | + |
| 62 | + Point converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 63 | + |
| 64 | + MultiPoint converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 65 | + |
| 66 | + Polygon converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 67 | + |
| 68 | + MultiPolygon converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 69 | + |
| 70 | + LineString converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 71 | + |
| 72 | + MultiLineString converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 73 | + |
| 74 | + GeometryCollection converted => WriteWithLength(converted, buf, lengthCache, parameter, async, cancellationToken), |
| 75 | + |
| 76 | + |
| 77 | + DBNull => WriteWithLength(DBNull.Value, buf, lengthCache, parameter, async, cancellationToken), |
| 78 | + null => WriteWithLength(DBNull.Value, buf, lengthCache, parameter, async, cancellationToken), |
| 79 | + _ => throw new InvalidCastException($"Can't write CLR type {value.GetType()} with handler type GeoJsonHandler") |
| 80 | + }; |
| 81 | + } |
| 82 | +} |
0 commit comments