From 84b5fd7649fc3338b9eb15189373129095163295 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sun, 6 Jun 2021 17:07:37 +0200 Subject: [PATCH 1/3] Refactor DefaultTypeHandlerFactory to remove reflection As part of this, PostgresType can now be injected into handlers after construction. Closes #3815 --- src/Npgsql.GeoJSON/Internal/GeoJSONHandler.cs | 2 +- .../Internal/LegacyPostgisHandler.cs | 3 +- .../Internal/NetTopologySuiteHandler.cs | 2 +- src/Npgsql.NodaTime/Internal/DateHandler.cs | 2 +- .../Internal/IntervalHandler.cs | 7 +- src/Npgsql.NodaTime/Internal/TimeHandler.cs | 7 +- src/Npgsql.NodaTime/Internal/TimeTzHandler.cs | 7 +- .../Internal/TimestampHandler.cs | 2 +- .../Internal/TimestampTzHandler.cs | 2 +- .../Internal/TypeHandlers/ArrayHandler.cs | 2 +- .../Internal/TypeHandlers/BitStringHandler.cs | 5 -- .../Internal/TypeHandlers/BoolHandler.cs | 4 -- .../Internal/TypeHandlers/ByteaHandler.cs | 6 -- .../CompositeHandlers/CompositeHandler.cs | 2 +- .../DateTimeHandlers/DateHandler.cs | 6 +- .../DateTimeHandlers/IntervalHandler.cs | 3 +- .../DateTimeHandlers/TimeHandler.cs | 3 +- .../DateTimeHandlers/TimeTzHandler.cs | 3 +- .../DateTimeHandlers/TimestampHandler.cs | 5 +- .../Internal/TypeHandlers/EnumHandler.cs | 2 +- .../FullTextSearchHandlers/TsQueryHandler.cs | 5 -- .../FullTextSearchHandlers/TsVectorHandler.cs | 5 -- .../GeometricHandlers/BoxHandler.cs | 5 -- .../GeometricHandlers/CircleHandler.cs | 5 -- .../GeometricHandlers/LineHandler.cs | 5 -- .../GeometricHandlers/LineSegmentHandler.cs | 5 -- .../GeometricHandlers/PathHandler.cs | 5 -- .../GeometricHandlers/PointHandler.cs | 4 -- .../GeometricHandlers/PolygonHandler.cs | 5 -- .../Internal/TypeHandlers/HstoreHandler.cs | 5 +- .../InternalTypeHandlers/Int2VectorHandler.cs | 2 +- .../InternalCharHandler.cs | 4 -- .../InternalTypeHandlers/OIDVectorHandler.cs | 2 +- .../InternalTypeHandlers/PgLsnHandler.cs | 3 - .../InternalTypeHandlers/TidHandler.cs | 4 -- .../Internal/TypeHandlers/JsonHandler.cs | 2 +- .../Internal/TypeHandlers/JsonPathHandler.cs | 5 +- .../NetworkHandlers/CidrHandler.cs | 10 +-- .../NetworkHandlers/InetHandler.cs | 7 -- .../NetworkHandlers/MacaddrHandler.cs | 6 -- .../NumericHandlers/DoubleHandler.cs | 9 +-- .../NumericHandlers/Int16Handler.cs | 9 +-- .../NumericHandlers/Int32Handler.cs | 8 +-- .../NumericHandlers/Int64Handler.cs | 9 +-- .../NumericHandlers/MoneyHandler.cs | 7 -- .../NumericHandlers/NumericHandler.cs | 7 -- .../NumericHandlers/SingleHandler.cs | 9 +-- .../NumericHandlers/UInt32Handler.cs | 6 -- .../Internal/TypeHandlers/RangeHandler.cs | 2 +- .../Internal/TypeHandlers/RecordHandler.cs | 2 +- .../Internal/TypeHandlers/TextHandler.cs | 5 +- .../Internal/TypeHandlers/UuidHandler.cs | 7 -- .../Internal/TypeHandlers/VoidHandler.cs | 3 - .../TypeHandling/DefaultTypeHandlerFactory.cs | 35 ---------- .../TypeHandling/NpgsqlSimpleTypeHandler.cs | 5 -- .../NpgsqlSimpleTypeHandlerWithPsv.cs | 7 -- .../TypeHandling/NpgsqlTypeHandler.cs | 8 +-- .../TypeHandling/NpgsqlTypeHandlerFactory.cs | 19 ++++- .../TypeHandling/NpgsqlTypeHandler`.cs | 5 -- src/Npgsql/TypeMapping/GlobalTypeMapper.cs | 69 +++++++++---------- src/Shared/CodeAnalysis20.cs | 7 ++ .../Npgsql.Benchmarks/TypeHandlers/Numeric.cs | 14 ++-- test/Npgsql.Benchmarks/TypeHandlers/Uuid.cs | 2 +- test/Npgsql.Tests/ReaderTests.cs | 5 +- test/Npgsql.Tests/TypeMapperTests.cs | 2 +- 65 files changed, 136 insertions(+), 294 deletions(-) delete mode 100644 src/Npgsql/Internal/TypeHandling/DefaultTypeHandlerFactory.cs diff --git a/src/Npgsql.GeoJSON/Internal/GeoJSONHandler.cs b/src/Npgsql.GeoJSON/Internal/GeoJSONHandler.cs index a8f0b4d148..09e9702ae0 100644 --- a/src/Npgsql.GeoJSON/Internal/GeoJSONHandler.cs +++ b/src/Npgsql.GeoJSON/Internal/GeoJSONHandler.cs @@ -60,8 +60,8 @@ sealed partial class GeoJsonHandler : NpgsqlTypeHandler, int _lastSrid; internal GeoJsonHandler(PostgresType postgresType, GeoJSONOptions options, CrsMap crsMap) - : base(postgresType) { + PostgresType = postgresType; _options = options; _crsMap = crsMap; } diff --git a/src/Npgsql.LegacyPostgis/Internal/LegacyPostgisHandler.cs b/src/Npgsql.LegacyPostgis/Internal/LegacyPostgisHandler.cs index 1dd6d7c120..62b2cf6d52 100644 --- a/src/Npgsql.LegacyPostgis/Internal/LegacyPostgisHandler.cs +++ b/src/Npgsql.LegacyPostgis/Internal/LegacyPostgisHandler.cs @@ -20,7 +20,8 @@ partial class LegacyPostgisHandler : NpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler { - public LegacyPostgisHandler(PostgresType postgresType) : base(postgresType) {} + public LegacyPostgisHandler(PostgresType postgresType) + => PostgresType = postgresType; #region Read diff --git a/src/Npgsql.NetTopologySuite/Internal/NetTopologySuiteHandler.cs b/src/Npgsql.NetTopologySuite/Internal/NetTopologySuiteHandler.cs index 7d0925508e..f1600566f9 100644 --- a/src/Npgsql.NetTopologySuite/Internal/NetTopologySuiteHandler.cs +++ b/src/Npgsql.NetTopologySuite/Internal/NetTopologySuiteHandler.cs @@ -25,8 +25,8 @@ partial class NetTopologySuiteHandler : NpgsqlTypeHandler, readonly LengthStream _lengthStream = new(); internal NetTopologySuiteHandler(PostgresType postgresType, PostGisReader reader, PostGisWriter writer) - : base(postgresType) { + PostgresType = postgresType; _reader = reader; _writer = writer; } diff --git a/src/Npgsql.NodaTime/Internal/DateHandler.cs b/src/Npgsql.NodaTime/Internal/DateHandler.cs index 45b6d09d53..e868f45ac6 100644 --- a/src/Npgsql.NodaTime/Internal/DateHandler.cs +++ b/src/Npgsql.NodaTime/Internal/DateHandler.cs @@ -28,8 +28,8 @@ sealed partial class DateHandler : NpgsqlSimpleTypeHandler, INpgsqlSi readonly BclDateHandler _bclHandler; internal DateHandler(PostgresType postgresType, bool convertInfinityDateTime) - : base(postgresType) { + PostgresType = postgresType; _convertInfinityDateTime = convertInfinityDateTime; _bclHandler = new BclDateHandler(postgresType, convertInfinityDateTime); } diff --git a/src/Npgsql.NodaTime/Internal/IntervalHandler.cs b/src/Npgsql.NodaTime/Internal/IntervalHandler.cs index 4f3335ecc1..579525dd8d 100644 --- a/src/Npgsql.NodaTime/Internal/IntervalHandler.cs +++ b/src/Npgsql.NodaTime/Internal/IntervalHandler.cs @@ -26,8 +26,11 @@ sealed partial class IntervalHandler : { readonly BclIntervalHandler _bclHandler; - internal IntervalHandler(PostgresType postgresType) : base(postgresType) - => _bclHandler = new BclIntervalHandler(postgresType); + internal IntervalHandler(PostgresType postgresType) + { + PostgresType = postgresType; + _bclHandler = new BclIntervalHandler(postgresType); + } public override Period Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) { diff --git a/src/Npgsql.NodaTime/Internal/TimeHandler.cs b/src/Npgsql.NodaTime/Internal/TimeHandler.cs index 63c744209d..0b92bb5334 100644 --- a/src/Npgsql.NodaTime/Internal/TimeHandler.cs +++ b/src/Npgsql.NodaTime/Internal/TimeHandler.cs @@ -26,8 +26,11 @@ sealed partial class TimeHandler : NpgsqlSimpleTypeHandler, INpgsqlSi { readonly BclTimeHandler _bclHandler; - internal TimeHandler(PostgresType postgresType) : base(postgresType) - => _bclHandler = new BclTimeHandler(postgresType); + internal TimeHandler(PostgresType postgresType) + { + PostgresType = postgresType; + _bclHandler = new BclTimeHandler(postgresType); + } // PostgreSQL time resolution == 1 microsecond == 10 ticks public override LocalTime Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql.NodaTime/Internal/TimeTzHandler.cs b/src/Npgsql.NodaTime/Internal/TimeTzHandler.cs index 73f455ca83..45569019e7 100644 --- a/src/Npgsql.NodaTime/Internal/TimeTzHandler.cs +++ b/src/Npgsql.NodaTime/Internal/TimeTzHandler.cs @@ -22,8 +22,11 @@ sealed partial class TimeTzHandler : NpgsqlSimpleTypeHandler, INpgsq { readonly BclTimeTzHandler _bclHandler; - internal TimeTzHandler(PostgresType postgresType) : base(postgresType) - => _bclHandler = new BclTimeTzHandler(postgresType); + internal TimeTzHandler(PostgresType postgresType) + { + PostgresType = postgresType; + _bclHandler = new BclTimeTzHandler(postgresType); + } // Adjust from 1 microsecond to 100ns. Time zone (in seconds) is inverted. public override OffsetTime Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql.NodaTime/Internal/TimestampHandler.cs b/src/Npgsql.NodaTime/Internal/TimestampHandler.cs index 97b930e065..060e3a594e 100644 --- a/src/Npgsql.NodaTime/Internal/TimestampHandler.cs +++ b/src/Npgsql.NodaTime/Internal/TimestampHandler.cs @@ -35,8 +35,8 @@ sealed partial class TimestampHandler : NpgsqlSimpleTypeHandler, INpgsq readonly BclTimestampHandler _bclHandler; internal TimestampHandler(PostgresType postgresType, bool convertInfinityDateTime) - : base(postgresType) { + PostgresType = postgresType; _convertInfinityDateTime = convertInfinityDateTime; _bclHandler = new BclTimestampHandler(postgresType, convertInfinityDateTime); } diff --git a/src/Npgsql.NodaTime/Internal/TimestampTzHandler.cs b/src/Npgsql.NodaTime/Internal/TimestampTzHandler.cs index cf357988bc..aab255cadb 100644 --- a/src/Npgsql.NodaTime/Internal/TimestampTzHandler.cs +++ b/src/Npgsql.NodaTime/Internal/TimestampTzHandler.cs @@ -33,8 +33,8 @@ sealed partial class TimestampTzHandler : NpgsqlSimpleTypeHandler, INpg readonly bool _convertInfinityDateTime; public TimestampTzHandler(PostgresType postgresType, bool convertInfinityDateTime) - : base(postgresType) { + PostgresType = postgresType; _dateTimeZoneProvider = DateTimeZoneProviders.Tzdb; _convertInfinityDateTime = convertInfinityDateTime; _bclHandler = new BclTimestampTzHandler(postgresType, convertInfinityDateTime); diff --git a/src/Npgsql/Internal/TypeHandlers/ArrayHandler.cs b/src/Npgsql/Internal/TypeHandlers/ArrayHandler.cs index af09f1e331..65ef203d7f 100644 --- a/src/Npgsql/Internal/TypeHandlers/ArrayHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/ArrayHandler.cs @@ -35,8 +35,8 @@ public abstract class ArrayHandler : NpgsqlTypeHandler /// protected ArrayHandler(PostgresType arrayPostgresType, NpgsqlTypeHandler elementHandler, ArrayNullabilityMode arrayNullabilityMode, int lowerBound = 1) - : base(arrayPostgresType) { + PostgresType = arrayPostgresType; LowerBound = lowerBound; ElementHandler = elementHandler; ArrayNullabilityMode = arrayNullabilityMode; diff --git a/src/Npgsql/Internal/TypeHandlers/BitStringHandler.cs b/src/Npgsql/Internal/TypeHandlers/BitStringHandler.cs index e0ab11bf9b..e047e00177 100644 --- a/src/Npgsql/Internal/TypeHandlers/BitStringHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/BitStringHandler.cs @@ -8,8 +8,6 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers { @@ -29,9 +27,6 @@ namespace Npgsql.Internal.TypeHandlers public partial class BitStringHandler : NpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler { - /// - public BitStringHandler(PostgresType postgresType) : base(postgresType) {} - internal override Type GetFieldType(FieldDescription? fieldDescription = null) => fieldDescription != null && fieldDescription.TypeModifier == 1 ? typeof(bool) : typeof(BitArray); diff --git a/src/Npgsql/Internal/TypeHandlers/BoolHandler.cs b/src/Npgsql/Internal/TypeHandlers/BoolHandler.cs index 66bed53db6..bbb2ac1007 100644 --- a/src/Npgsql/Internal/TypeHandlers/BoolHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/BoolHandler.cs @@ -1,6 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; namespace Npgsql.Internal.TypeHandlers { @@ -16,9 +15,6 @@ namespace Npgsql.Internal.TypeHandlers /// public partial class BoolHandler : NpgsqlSimpleTypeHandler { - /// - public BoolHandler(PostgresType postgresType) : base(postgresType) {} - /// public override bool Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => buf.ReadByte() != 0; diff --git a/src/Npgsql/Internal/TypeHandlers/ByteaHandler.cs b/src/Npgsql/Internal/TypeHandlers/ByteaHandler.cs index e7bb058c73..47b10779a3 100644 --- a/src/Npgsql/Internal/TypeHandlers/ByteaHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/ByteaHandler.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; namespace Npgsql.Internal.TypeHandlers { @@ -22,11 +21,6 @@ public partial class ByteaHandler : NpgsqlTypeHandler, INpgsqlTypeHandle , INpgsqlTypeHandler>, INpgsqlTypeHandler> #endif { - /// - /// Constructs a . - /// - public ByteaHandler(PostgresType postgresType) : base(postgresType) {} - /// public override async ValueTask Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription? fieldDescription = null) { diff --git a/src/Npgsql/Internal/TypeHandlers/CompositeHandlers/CompositeHandler.cs b/src/Npgsql/Internal/TypeHandlers/CompositeHandlers/CompositeHandler.cs index c4238ed858..4faba0e546 100644 --- a/src/Npgsql/Internal/TypeHandlers/CompositeHandlers/CompositeHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/CompositeHandlers/CompositeHandler.cs @@ -25,8 +25,8 @@ partial class CompositeHandler : NpgsqlTypeHandler, ICompositeHandler public Type CompositeType => typeof(T); public CompositeHandler(PostgresCompositeType postgresType, ConnectorTypeMapper typeMapper, INpgsqlNameTranslator nameTranslator) - : base(postgresType) { + PostgresType = postgresType; _typeMapper = typeMapper; _nameTranslator = nameTranslator; } diff --git a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/DateHandler.cs b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/DateHandler.cs index 3f6c6b5e71..72dc76509d 100644 --- a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/DateHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/DateHandler.cs @@ -48,8 +48,10 @@ public partial class DateHandler : NpgsqlSimpleTypeHandlerWithPsv /// public DateHandler(PostgresType postgresType, bool convertInfinityDateTime) - : base(postgresType) - => _convertInfinityDateTime = convertInfinityDateTime; + { + PostgresType = postgresType; + _convertInfinityDateTime = convertInfinityDateTime; + } #region Read diff --git a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/IntervalHandler.cs b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/IntervalHandler.cs index 2a5e0c4ffb..fcc8cf5e22 100644 --- a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/IntervalHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/IntervalHandler.cs @@ -41,7 +41,8 @@ public partial class IntervalHandler : NpgsqlSimpleTypeHandlerWithPsv /// Constructs an /// - public IntervalHandler(PostgresType postgresType) : base(postgresType) {} + public IntervalHandler(PostgresType postgresType) + => PostgresType = postgresType; /// public override TimeSpan Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeHandler.cs b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeHandler.cs index 07c717cc2f..720cd94088 100644 --- a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeHandler.cs @@ -45,7 +45,8 @@ public partial class TimeHandler : NpgsqlSimpleTypeHandler /// /// Constructs a . /// - public TimeHandler(PostgresType postgresType) : base(postgresType) {} + public TimeHandler(PostgresType postgresType) + => PostgresType = postgresType; // PostgreSQL time resolution == 1 microsecond == 10 ticks /// diff --git a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeTzHandler.cs b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeTzHandler.cs index 365c688256..459d2ce901 100644 --- a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeTzHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimeTzHandler.cs @@ -43,7 +43,8 @@ public partial class TimeTzHandler : NpgsqlSimpleTypeHandler, IN /// /// Constructs an . /// - public TimeTzHandler(PostgresType postgresType) : base(postgresType) {} + public TimeTzHandler(PostgresType postgresType) + => PostgresType = postgresType; #region Read diff --git a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimestampHandler.cs b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimestampHandler.cs index 1dba4248e5..95395cd12f 100644 --- a/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimestampHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/DateTimeHandlers/TimestampHandler.cs @@ -50,7 +50,10 @@ public partial class TimestampHandler : NpgsqlSimpleTypeHandlerWithPsv. /// public TimestampHandler(PostgresType postgresType, bool convertInfinityDateTime) - : base(postgresType) => ConvertInfinityDateTime = convertInfinityDateTime; + { + PostgresType = postgresType; + ConvertInfinityDateTime = convertInfinityDateTime; + } #region Read diff --git a/src/Npgsql/Internal/TypeHandlers/EnumHandler.cs b/src/Npgsql/Internal/TypeHandlers/EnumHandler.cs index 1b97c14403..5816163898 100644 --- a/src/Npgsql/Internal/TypeHandlers/EnumHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/EnumHandler.cs @@ -32,9 +32,9 @@ partial class EnumHandler : NpgsqlSimpleTypeHandler, IEnumHandler #region Construction internal EnumHandler(PostgresType postgresType, Dictionary enumToLabel, Dictionary labelToEnum) - : base(postgresType) { Debug.Assert(typeof(TEnum).GetTypeInfo().IsEnum, "EnumHandler instantiated for non-enum type"); + PostgresType = postgresType; _enumToLabel = enumToLabel; _labelToEnum = labelToEnum; } diff --git a/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsQueryHandler.cs b/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsQueryHandler.cs index fdc38aec5d..f8319c35fc 100644 --- a/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsQueryHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsQueryHandler.cs @@ -5,8 +5,6 @@ using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; // TODO: Need to work on the nullability here @@ -35,9 +33,6 @@ public partial class TsQueryHandler : NpgsqlTypeHandler, readonly Stack _stack = new(); - /// - public TsQueryHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsVectorHandler.cs b/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsVectorHandler.cs index 2885de55d8..a1671c9884 100644 --- a/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsVectorHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/FullTextSearchHandlers/TsVectorHandler.cs @@ -6,8 +6,6 @@ using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.FullTextSearchHandlers @@ -28,9 +26,6 @@ public partial class TsVectorHandler : NpgsqlTypeHandler // 2 (num_pos) + sizeof(int16) * 256 (max_num_pos (positions/wegihts)) const int MaxSingleLexemeBytes = 2561; - /// - public TsVectorHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/BoxHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/BoxHandler.cs index be60fdeff6..d6b0d0ec3f 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/BoxHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/BoxHandler.cs @@ -1,7 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -18,9 +16,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class BoxHandler : NpgsqlSimpleTypeHandler { - /// - public BoxHandler(PostgresType postgresType) : base(postgresType) {} - /// public override NpgsqlBox Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => new( diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/CircleHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/CircleHandler.cs index d460ca6ede..124224c0b5 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/CircleHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/CircleHandler.cs @@ -1,7 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -18,9 +16,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class CircleHandler : NpgsqlSimpleTypeHandler { - /// - public CircleHandler(PostgresType postgresType) : base(postgresType) {} - /// public override NpgsqlCircle Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => new(buf.ReadDouble(), buf.ReadDouble(), buf.ReadDouble()); diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineHandler.cs index a003dbb8ea..4e23d547f8 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineHandler.cs @@ -1,7 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -18,9 +16,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class LineHandler : NpgsqlSimpleTypeHandler { - /// - public LineHandler(PostgresType postgresType) : base(postgresType) {} - /// public override NpgsqlLine Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => new(buf.ReadDouble(), buf.ReadDouble(), buf.ReadDouble()); diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineSegmentHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineSegmentHandler.cs index b6c220e3cc..18b62a61ca 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineSegmentHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/LineSegmentHandler.cs @@ -1,7 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -18,9 +16,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class LineSegmentHandler : NpgsqlSimpleTypeHandler { - /// - public LineSegmentHandler(PostgresType postgresType) : base(postgresType) {} - /// public override NpgsqlLSeg Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => new(buf.ReadDouble(), buf.ReadDouble(), buf.ReadDouble(), buf.ReadDouble()); diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PathHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PathHandler.cs index 1d98235efb..21eae4048d 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PathHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PathHandler.cs @@ -3,8 +3,6 @@ using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -21,9 +19,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class PathHandler : NpgsqlTypeHandler { - /// - public PathHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PointHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PointHandler.cs index a6cf3950a0..9823ccc36a 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PointHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PointHandler.cs @@ -1,6 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -17,9 +16,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class PointHandler : NpgsqlSimpleTypeHandler { - /// - public PointHandler(PostgresType postgresType) : base(postgresType) {} - /// public override NpgsqlPoint Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => new(buf.ReadDouble(), buf.ReadDouble()); diff --git a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PolygonHandler.cs b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PolygonHandler.cs index b1d5360bc7..62b63de1a0 100644 --- a/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PolygonHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/GeometricHandlers/PolygonHandler.cs @@ -2,8 +2,6 @@ using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.GeometricHandlers @@ -20,9 +18,6 @@ namespace Npgsql.Internal.TypeHandlers.GeometricHandlers /// public partial class PolygonHandler : NpgsqlTypeHandler { - /// - public PolygonHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/HstoreHandler.cs b/src/Npgsql/Internal/TypeHandlers/HstoreHandler.cs index e61571642b..3d9c3b0d01 100644 --- a/src/Npgsql/Internal/TypeHandlers/HstoreHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/HstoreHandler.cs @@ -56,7 +56,10 @@ public class HstoreHandler : readonly TextHandler _textHandler; internal HstoreHandler(PostgresType postgresType, NpgsqlConnector connector) - : base(postgresType) => _textHandler = new TextHandler(postgresType, connector); + { + PostgresType = postgresType; + _textHandler = new TextHandler(postgresType, connector); + } #region Write diff --git a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/Int2VectorHandler.cs b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/Int2VectorHandler.cs index b2d0d6ce2c..0e285aa893 100644 --- a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/Int2VectorHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/Int2VectorHandler.cs @@ -23,7 +23,7 @@ public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlCo class Int2VectorHandler : ArrayHandler { public Int2VectorHandler(PostgresType arrayPostgresType, PostgresType postgresShortType) - : base(arrayPostgresType, new Int16Handler(postgresShortType), ArrayNullabilityMode.Never, 0) { } + : base(arrayPostgresType, new Int16Handler { PostgresType = postgresShortType }, ArrayNullabilityMode.Never, 0) { } public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandler>(arrayBackendType, this, arrayNullabilityMode); diff --git a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/InternalCharHandler.cs b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/InternalCharHandler.cs index bb23545290..b2dfea403e 100644 --- a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/InternalCharHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/InternalCharHandler.cs @@ -1,6 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; namespace Npgsql.Internal.TypeHandlers.InternalTypeHandlers { @@ -17,9 +16,6 @@ namespace Npgsql.Internal.TypeHandlers.InternalTypeHandlers public partial class InternalCharHandler : NpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler { - /// - public InternalCharHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/OIDVectorHandler.cs b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/OIDVectorHandler.cs index f5bc4281d4..13b7524edd 100644 --- a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/OIDVectorHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/OIDVectorHandler.cs @@ -23,7 +23,7 @@ public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlCo class OIDVectorHandler : ArrayHandler { public OIDVectorHandler(PostgresType oidvectorType, PostgresType oidType) - : base(oidvectorType, new UInt32Handler(oidType), ArrayNullabilityMode.Never, 0) { } + : base(oidvectorType, new UInt32Handler { PostgresType = oidType }, ArrayNullabilityMode.Never, 0) { } public override ArrayHandler CreateArrayHandler(PostgresArrayType arrayBackendType, ArrayNullabilityMode arrayNullabilityMode) => new ArrayHandler>(arrayBackendType, this, arrayNullabilityMode); diff --git a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/PgLsnHandler.cs b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/PgLsnHandler.cs index 1642fe29eb..35be636b32 100644 --- a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/PgLsnHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/PgLsnHandler.cs @@ -1,15 +1,12 @@ using System.Diagnostics; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.InternalTypeHandlers { partial class PgLsnHandler : NpgsqlSimpleTypeHandler { - public PgLsnHandler(PostgresType postgresType) : base(postgresType) {} - #region Read public override NpgsqlLogSequenceNumber Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/TidHandler.cs b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/TidHandler.cs index 9ac07b3afd..4d99e574ab 100644 --- a/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/TidHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/InternalTypeHandlers/TidHandler.cs @@ -1,16 +1,12 @@ using System.Diagnostics; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.InternalTypeHandlers { partial class TidHandler : NpgsqlSimpleTypeHandler { - public TidHandler(PostgresType postgresType) : base(postgresType) {} - #region Read public override NpgsqlTid Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql/Internal/TypeHandlers/JsonHandler.cs b/src/Npgsql/Internal/TypeHandlers/JsonHandler.cs index 429a51952f..22b5b6b4d0 100644 --- a/src/Npgsql/Internal/TypeHandlers/JsonHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/JsonHandler.cs @@ -90,8 +90,8 @@ public class JsonHandler : NpgsqlTypeHandler, ITextReaderHandler /// protected internal JsonHandler(PostgresType postgresType, NpgsqlConnector connector, bool isJsonb, JsonSerializerOptions? serializerOptions = null) - : base(postgresType) { + PostgresType = postgresType; _serializerOptions = serializerOptions ?? DefaultSerializerOptions; _isJsonb = isJsonb; _headerLen = isJsonb ? 1 : 0; diff --git a/src/Npgsql/Internal/TypeHandlers/JsonPathHandler.cs b/src/Npgsql/Internal/TypeHandlers/JsonPathHandler.cs index 28a9ded337..4fb1c1a803 100644 --- a/src/Npgsql/Internal/TypeHandlers/JsonPathHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/JsonPathHandler.cs @@ -48,7 +48,10 @@ public partial class JsonPathHandler : NpgsqlTypeHandler, ITextReaderHan /// protected internal JsonPathHandler(PostgresType postgresType, NpgsqlConnector connector) - : base(postgresType) => _textHandler = new TextHandler(postgresType, connector); + { + PostgresType = postgresType; + _textHandler = new TextHandler(postgresType, connector); + } /// public override async ValueTask Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/CidrHandler.cs b/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/CidrHandler.cs index 6db28a3688..7f9033c4a8 100644 --- a/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/CidrHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/CidrHandler.cs @@ -1,11 +1,6 @@ -using System; -using System.Net; -using System.Threading; -using System.Threading.Tasks; +using System.Net; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; #pragma warning disable 618 @@ -24,9 +19,6 @@ namespace Npgsql.Internal.TypeHandlers.NetworkHandlers /// public partial class CidrHandler : NpgsqlSimpleTypeHandler<(IPAddress Address, int Subnet)>, INpgsqlSimpleTypeHandler { - /// - public CidrHandler(PostgresType postgresType) : base(postgresType) {} - /// public override (IPAddress Address, int Subnet) Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => InetHandler.DoRead(buf, len, fieldDescription, true); diff --git a/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/InetHandler.cs b/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/InetHandler.cs index a36917e17f..d463fbcbde 100644 --- a/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/InetHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/InetHandler.cs @@ -2,12 +2,8 @@ using System.Diagnostics; using System.Net; using System.Net.Sockets; -using System.Threading; -using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; using NpgsqlTypes; #pragma warning disable 618 @@ -32,9 +28,6 @@ public partial class InetHandler : NpgsqlSimpleTypeHandlerWithPsv - public InetHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/MacaddrHandler.cs b/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/MacaddrHandler.cs index 39c5b60b98..9a013b7aed 100644 --- a/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/MacaddrHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NetworkHandlers/MacaddrHandler.cs @@ -2,9 +2,6 @@ using System.Net.NetworkInformation; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NetworkHandlers { @@ -20,9 +17,6 @@ namespace Npgsql.Internal.TypeHandlers.NetworkHandlers /// public partial class MacaddrHandler : NpgsqlSimpleTypeHandler { - /// - public MacaddrHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/DoubleHandler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/DoubleHandler.cs index ba5231fc56..5d31933200 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/DoubleHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/DoubleHandler.cs @@ -1,9 +1,5 @@ -using System.Data; -using Npgsql.BackendMessages; +using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -19,9 +15,6 @@ namespace Npgsql.Internal.TypeHandlers.NumericHandlers /// public partial class DoubleHandler : NpgsqlSimpleTypeHandler { - /// - public DoubleHandler(PostgresType postgresType) : base(postgresType) {} - /// public override double Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => buf.ReadDouble(); diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int16Handler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int16Handler.cs index 783351f43d..7e3c1c8ef9 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int16Handler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int16Handler.cs @@ -1,9 +1,5 @@ -using System.Data; -using Npgsql.BackendMessages; +using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -21,9 +17,6 @@ public partial class Int16Handler : NpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler { - /// - public Int16Handler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int32Handler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int32Handler.cs index 12badcd827..16a2dd5e71 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int32Handler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int32Handler.cs @@ -1,8 +1,5 @@ -using System; -using System.Threading.Tasks; -using Npgsql.BackendMessages; +using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -20,9 +17,6 @@ public partial class Int32Handler : NpgsqlSimpleTypeHandler, INpgsqlSimpleT INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler { - /// - public Int32Handler(PostgresType postgresType) : base(postgresType) {} - #region Read public override int Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int64Handler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int64Handler.cs index 051f51f393..b2723a9750 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int64Handler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/Int64Handler.cs @@ -1,9 +1,5 @@ -using System.Data; -using Npgsql.BackendMessages; +using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -21,9 +17,6 @@ public partial class Int64Handler : NpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler { - /// - public Int64Handler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/MoneyHandler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/MoneyHandler.cs index 13a9545e6e..14eacd918c 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/MoneyHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/MoneyHandler.cs @@ -1,10 +1,6 @@ using System; -using System.Data; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -22,9 +18,6 @@ public partial class MoneyHandler : NpgsqlSimpleTypeHandler { const int MoneyScale = 2; - /// - public MoneyHandler(PostgresType postgresType) : base(postgresType) {} - /// public override decimal Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => new DecimalRaw(buf.ReadInt64()) { Scale = MoneyScale }.Value; diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/NumericHandler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/NumericHandler.cs index 9b8a1d00a0..41f673c284 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/NumericHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/NumericHandler.cs @@ -1,14 +1,10 @@ using System; -using System.Data; using System.Globalization; using System.Numerics; using System.Threading; using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -26,9 +22,6 @@ public partial class NumericHandler : NpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler, INpgsqlTypeHandler { - /// - public NumericHandler(PostgresType postgresType) : base(postgresType) { } - const int MaxDecimalScale = 28; const int SignPositive = 0x0000; diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/SingleHandler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/SingleHandler.cs index 3cffb9ebd6..6f0a86a075 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/SingleHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/SingleHandler.cs @@ -1,9 +1,5 @@ -using System.Data; -using Npgsql.BackendMessages; +using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -19,9 +15,6 @@ namespace Npgsql.Internal.TypeHandlers.NumericHandlers /// public partial class SingleHandler : NpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler { - /// - public SingleHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/UInt32Handler.cs b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/UInt32Handler.cs index cd5271afcf..90c422f4fe 100644 --- a/src/Npgsql/Internal/TypeHandlers/NumericHandlers/UInt32Handler.cs +++ b/src/Npgsql/Internal/TypeHandlers/NumericHandlers/UInt32Handler.cs @@ -1,8 +1,5 @@ using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers.NumericHandlers { @@ -18,9 +15,6 @@ namespace Npgsql.Internal.TypeHandlers.NumericHandlers /// public partial class UInt32Handler : NpgsqlSimpleTypeHandler { - /// - public UInt32Handler(PostgresType postgresType) : base(postgresType) {} - /// public override uint Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => buf.ReadUInt32(); diff --git a/src/Npgsql/Internal/TypeHandlers/RangeHandler.cs b/src/Npgsql/Internal/TypeHandlers/RangeHandler.cs index 1c6a2988dc..9f9cc6d1fe 100644 --- a/src/Npgsql/Internal/TypeHandlers/RangeHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/RangeHandler.cs @@ -48,8 +48,8 @@ public RangeHandler(PostgresType rangePostgresType, NpgsqlTypeHandler elementHan /// protected RangeHandler(PostgresType rangePostgresType, NpgsqlTypeHandler elementHandler, Type[] supportedElementClrTypes) - : base(rangePostgresType) { + PostgresType = rangePostgresType; _elementHandler = elementHandler; SupportedRangeClrTypes = supportedElementClrTypes; } diff --git a/src/Npgsql/Internal/TypeHandlers/RecordHandler.cs b/src/Npgsql/Internal/TypeHandlers/RecordHandler.cs index dd96ef2a82..2a84284c1c 100644 --- a/src/Npgsql/Internal/TypeHandlers/RecordHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/RecordHandler.cs @@ -31,8 +31,8 @@ partial class RecordHandler : NpgsqlTypeHandler readonly ConnectorTypeMapper _typeMapper; public RecordHandler(PostgresType postgresType, ConnectorTypeMapper typeMapper) - : base(postgresType) { + PostgresType = postgresType; _typeMapper = typeMapper; } diff --git a/src/Npgsql/Internal/TypeHandlers/TextHandler.cs b/src/Npgsql/Internal/TypeHandlers/TextHandler.cs index b594b81430..cc7e9ad853 100644 --- a/src/Npgsql/Internal/TypeHandlers/TextHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/TextHandler.cs @@ -61,7 +61,10 @@ protected internal TextHandler(PostgresType postgresType, NpgsqlConnector connec /// protected internal TextHandler(PostgresType postgresType, Encoding encoding) - : base(postgresType) => _encoding = encoding; + { + PostgresType = postgresType; + _encoding = encoding; + } #region Read diff --git a/src/Npgsql/Internal/TypeHandlers/UuidHandler.cs b/src/Npgsql/Internal/TypeHandlers/UuidHandler.cs index 5bb16dc5c1..6af6c93fd5 100644 --- a/src/Npgsql/Internal/TypeHandlers/UuidHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/UuidHandler.cs @@ -1,11 +1,7 @@ using System; -using System.Data; using System.Runtime.InteropServices; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; -using Npgsql.TypeMapping; -using NpgsqlTypes; namespace Npgsql.Internal.TypeHandlers { @@ -35,9 +31,6 @@ public partial class UuidHandler : NpgsqlSimpleTypeHandler // | 16 | 2 | Data3 | Native | Big | // | 64 | 8 | Data4 | Big | Big | - /// - public UuidHandler(PostgresType postgresType) : base(postgresType) {} - /// public override Guid Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) { diff --git a/src/Npgsql/Internal/TypeHandlers/VoidHandler.cs b/src/Npgsql/Internal/TypeHandlers/VoidHandler.cs index a2fd9cb998..42078b5ac6 100644 --- a/src/Npgsql/Internal/TypeHandlers/VoidHandler.cs +++ b/src/Npgsql/Internal/TypeHandlers/VoidHandler.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Npgsql.BackendMessages; using Npgsql.Internal.TypeHandling; -using Npgsql.PostgresTypes; namespace Npgsql.Internal.TypeHandlers { @@ -12,8 +11,6 @@ namespace Npgsql.Internal.TypeHandlers /// class VoidHandler : NpgsqlSimpleTypeHandler { - public VoidHandler(PostgresType postgresType) : base(postgresType) {} - public override DBNull Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) => DBNull.Value; diff --git a/src/Npgsql/Internal/TypeHandling/DefaultTypeHandlerFactory.cs b/src/Npgsql/Internal/TypeHandling/DefaultTypeHandlerFactory.cs deleted file mode 100644 index c0ccdd94ca..0000000000 --- a/src/Npgsql/Internal/TypeHandling/DefaultTypeHandlerFactory.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Reflection; -using Npgsql.PostgresTypes; - -namespace Npgsql.Internal.TypeHandling -{ - /// - /// A type handler factory used to instantiate Npgsql's built-in type handlers. - /// - class DefaultTypeHandlerFactory : NpgsqlTypeHandlerFactory - { - readonly Type _handlerType; - - internal DefaultTypeHandlerFactory(Type handlerType) - { - // Recursively look for the TypeHandler superclass to extract its T as the - // DefaultValueType - Type? baseClass = handlerType; - while (!baseClass.GetTypeInfo().IsGenericType || baseClass.GetGenericTypeDefinition() != typeof(NpgsqlTypeHandler<>)) - { - baseClass = baseClass.GetTypeInfo().BaseType; - if (baseClass == null) - throw new Exception($"Npgsql type handler {handlerType} doesn't inherit from TypeHandler<>?"); - } - - DefaultValueType = baseClass.GetGenericArguments()[0]; - _handlerType = handlerType; - } - - public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn) - => (NpgsqlTypeHandler)Activator.CreateInstance(_handlerType, pgType)!; - - public override Type DefaultValueType { get; } - } -} diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandler.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandler.cs index 631a3c4287..64151d3b8e 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandler.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandler.cs @@ -19,11 +19,6 @@ namespace Npgsql.Internal.TypeHandling /// public abstract class NpgsqlSimpleTypeHandler : NpgsqlTypeHandler, INpgsqlSimpleTypeHandler { - /// - /// Constructs an . - /// - protected NpgsqlSimpleTypeHandler(PostgresType postgresType) : base(postgresType) {} - /// /// Reads a value of type with the given length from the provided buffer, /// with the assumption that it is entirely present in the provided memory buffer and no I/O will be diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandlerWithPsv.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandlerWithPsv.cs index bedf924b1c..861df91903 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandlerWithPsv.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlSimpleTypeHandlerWithPsv.cs @@ -23,13 +23,6 @@ namespace Npgsql.Internal.TypeHandling /// The provider-specific CLR type that this handler will read and write. public abstract class NpgsqlSimpleTypeHandlerWithPsv : NpgsqlSimpleTypeHandler, INpgsqlSimpleTypeHandler { - /// - /// Constructs an - /// - /// - protected NpgsqlSimpleTypeHandlerWithPsv(PostgresType postgresType) - : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs index 5cbbd95662..e918dec0b8 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs @@ -18,15 +18,11 @@ namespace Npgsql.Internal.TypeHandling /// public abstract class NpgsqlTypeHandler { + // TODO: Make this required in C# 10 /// /// The PostgreSQL type handled by this type handler. /// - internal PostgresType PostgresType { get; } - - /// - /// Constructs a . - /// - protected NpgsqlTypeHandler(PostgresType postgresType) => PostgresType = postgresType; + public PostgresType PostgresType { get; init; } = null!; #region Read diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs index b5113ffc2a..eb2359fa48 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using Npgsql.PostgresTypes; using Npgsql.TypeMapping; @@ -42,9 +43,25 @@ public abstract class NpgsqlTypeHandlerFactory : NpgsqlTypeHandlerFact /// public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn) - => Create(pgType, conn); + { + var handler = Create(pgType, conn); + Debug.Assert(handler.PostgresType is not null); + return handler; + } /// public override Type DefaultValueType => typeof(TDefault); } + + /// + /// A type handler factory used to instantiate Npgsql's built-in type handlers. + /// + class DefaultTypeHandlerFactory : NpgsqlTypeHandlerFactory + where THandler : NpgsqlTypeHandler, new() + { + public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn) + => new THandler { PostgresType = pgType }; + + public override Type DefaultValueType => typeof(TDefault); + } } diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler`.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler`.cs index 3abb0a6f8b..c962528bc4 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler`.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler`.cs @@ -22,11 +22,6 @@ namespace Npgsql.Internal.TypeHandling /// public abstract class NpgsqlTypeHandler : NpgsqlTypeHandler, INpgsqlTypeHandler { - /// - /// Constructs an . - /// - protected NpgsqlTypeHandler(PostgresType postgresType) : base(postgresType) {} - #region Read /// diff --git a/src/Npgsql/TypeMapping/GlobalTypeMapper.cs b/src/Npgsql/TypeMapping/GlobalTypeMapper.cs index 34dd14bd7c..2b1cd93ab4 100644 --- a/src/Npgsql/TypeMapping/GlobalTypeMapper.cs +++ b/src/Npgsql/TypeMapping/GlobalTypeMapper.cs @@ -220,7 +220,7 @@ void SetupNumericHandlers() DbTypes = new[] { DbType.Int16, DbType.Byte, DbType.SByte }, InferredDbType = DbType.Int16, ClrTypes = new[] { typeof(short), typeof(byte), typeof(sbyte) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(Int16Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -229,7 +229,7 @@ void SetupNumericHandlers() NpgsqlDbType = NpgsqlDbType.Integer, DbTypes = new[] { DbType.Int32 }, ClrTypes = new[] { typeof(int) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(Int32Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -238,7 +238,7 @@ void SetupNumericHandlers() NpgsqlDbType = NpgsqlDbType.Bigint, DbTypes = new[] { DbType.Int64 }, ClrTypes = new[] { typeof(long) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(Int64Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -247,7 +247,7 @@ void SetupNumericHandlers() NpgsqlDbType = NpgsqlDbType.Real, DbTypes = new[] { DbType.Single }, ClrTypes = new[] { typeof(float) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(SingleHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -256,7 +256,7 @@ void SetupNumericHandlers() NpgsqlDbType = NpgsqlDbType.Double, DbTypes = new[] { DbType.Double }, ClrTypes = new[] { typeof(double) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(DoubleHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -266,7 +266,7 @@ void SetupNumericHandlers() DbTypes = new[] { DbType.Decimal, DbType.VarNumeric }, InferredDbType = DbType.Decimal, ClrTypes = new[] { typeof(decimal), typeof(BigInteger) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(NumericHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -274,7 +274,7 @@ void SetupNumericHandlers() PgTypeName = "money", NpgsqlDbType = NpgsqlDbType.Money, DbTypes = new[] { DbType.Currency }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(MoneyHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } @@ -365,7 +365,6 @@ void SetupTextHandlers() NpgsqlDbType = NpgsqlDbType.JsonPath, TypeHandlerFactory = new JsonPathHandlerFactory() }.Build()); - } void SetupDateTimeHandlers() @@ -437,7 +436,7 @@ void SetupNetworkHandlers() { PgTypeName = "cidr", NpgsqlDbType = NpgsqlDbType.Cidr, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(CidrHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); var inetClrTypes = new List @@ -457,14 +456,14 @@ void SetupNetworkHandlers() PgTypeName = "inet", NpgsqlDbType = NpgsqlDbType.Inet, ClrTypes = inetClrTypes.ToArray(), - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(InetHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "macaddr8", NpgsqlDbType = NpgsqlDbType.MacAddr8, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(MacaddrHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -472,7 +471,7 @@ void SetupNetworkHandlers() PgTypeName = "macaddr", NpgsqlDbType = NpgsqlDbType.MacAddr, ClrTypes = new[] { typeof(PhysicalAddress) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(MacaddrHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } @@ -487,7 +486,7 @@ void SetupFullTextSearchHandlers() typeof(NpgsqlTsQuery), typeof(NpgsqlTsQueryAnd), typeof(NpgsqlTsQueryEmpty), typeof(NpgsqlTsQueryFollowedBy), typeof(NpgsqlTsQueryLexeme), typeof(NpgsqlTsQueryNot), typeof(NpgsqlTsQueryOr), typeof(NpgsqlTsQueryBinOp) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(TsQueryHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -495,7 +494,7 @@ void SetupFullTextSearchHandlers() PgTypeName = "tsvector", NpgsqlDbType = NpgsqlDbType.TsVector, ClrTypes = new[] { typeof(NpgsqlTsVector) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(TsVectorHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } @@ -506,7 +505,7 @@ void SetupGeometryHandlers() PgTypeName = "box", NpgsqlDbType = NpgsqlDbType.Box, ClrTypes = new[] { typeof(NpgsqlBox) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(BoxHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -514,7 +513,7 @@ void SetupGeometryHandlers() PgTypeName = "circle", NpgsqlDbType = NpgsqlDbType.Circle, ClrTypes = new[] { typeof(NpgsqlCircle) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(CircleHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -522,7 +521,7 @@ void SetupGeometryHandlers() PgTypeName = "line", NpgsqlDbType = NpgsqlDbType.Line, ClrTypes = new[] { typeof(NpgsqlLine) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(LineHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -530,7 +529,7 @@ void SetupGeometryHandlers() PgTypeName = "lseg", NpgsqlDbType = NpgsqlDbType.LSeg, ClrTypes = new[] { typeof(NpgsqlLSeg) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(LineSegmentHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -538,7 +537,7 @@ void SetupGeometryHandlers() PgTypeName = "path", NpgsqlDbType = NpgsqlDbType.Path, ClrTypes = new[] { typeof(NpgsqlPath) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(PathHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -546,7 +545,7 @@ void SetupGeometryHandlers() PgTypeName = "point", NpgsqlDbType = NpgsqlDbType.Point, ClrTypes = new[] { typeof(NpgsqlPoint) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(PointHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -554,7 +553,7 @@ void SetupGeometryHandlers() PgTypeName = "polygon", NpgsqlDbType = NpgsqlDbType.Polygon, ClrTypes = new[] { typeof(NpgsqlPolygon) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(PolygonHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } @@ -588,35 +587,35 @@ void SetupUIntHandlers() { PgTypeName = "oid", NpgsqlDbType = NpgsqlDbType.Oid, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(UInt32Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "xid", NpgsqlDbType = NpgsqlDbType.Xid, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(UInt32Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "cid", NpgsqlDbType = NpgsqlDbType.Cid, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(UInt32Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "regtype", NpgsqlDbType = NpgsqlDbType.Regtype, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(UInt32Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "regconfig", NpgsqlDbType = NpgsqlDbType.Regconfig, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(UInt32Handler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } @@ -628,7 +627,7 @@ void SetupMiscHandlers() NpgsqlDbType = NpgsqlDbType.Boolean, DbTypes = new[] { DbType.Boolean }, ClrTypes = new[] { typeof(bool) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(BoolHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -645,7 +644,7 @@ void SetupMiscHandlers() typeof(Memory) #endif }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(ByteaHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -653,14 +652,14 @@ void SetupMiscHandlers() PgTypeName = "bit varying", NpgsqlDbType = NpgsqlDbType.Varbit, ClrTypes = new[] { typeof(BitArray), typeof(BitVector32) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(BitStringHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "bit", NpgsqlDbType = NpgsqlDbType.Bit, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(BitStringHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -684,7 +683,7 @@ void SetupMiscHandlers() NpgsqlDbType = NpgsqlDbType.Uuid, DbTypes = new[] { DbType.Guid }, ClrTypes = new[] { typeof(Guid) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(UuidHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -696,7 +695,7 @@ void SetupMiscHandlers() AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "void", - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(VoidHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } @@ -721,7 +720,7 @@ void SetupInternalHandlers() PgTypeName = "pg_lsn", NpgsqlDbType = NpgsqlDbType.PgLsn, ClrTypes = new[] { typeof(NpgsqlLogSequenceNumber) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(PgLsnHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder @@ -729,14 +728,14 @@ void SetupInternalHandlers() PgTypeName = "tid", NpgsqlDbType = NpgsqlDbType.Tid, ClrTypes = new[] { typeof(NpgsqlTid) }, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(TidHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); AddMapping(new NpgsqlTypeMappingBuilder { PgTypeName = "char", NpgsqlDbType = NpgsqlDbType.InternalChar, - TypeHandlerFactory = new DefaultTypeHandlerFactory(typeof(InternalCharHandler)) + TypeHandlerFactory = new DefaultTypeHandlerFactory() }.Build()); } } diff --git a/src/Shared/CodeAnalysis20.cs b/src/Shared/CodeAnalysis20.cs index ed41012925..c3a15c16c3 100644 --- a/src/Shared/CodeAnalysis20.cs +++ b/src/Shared/CodeAnalysis20.cs @@ -64,3 +64,10 @@ sealed class NotNullWhenAttribute : Attribute } } #endif + +#if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices +{ + internal static class IsExternalInit {} +} +#endif diff --git a/test/Npgsql.Benchmarks/TypeHandlers/Numeric.cs b/test/Npgsql.Benchmarks/TypeHandlers/Numeric.cs index 868d766d58..17d61584c4 100644 --- a/test/Npgsql.Benchmarks/TypeHandlers/Numeric.cs +++ b/test/Npgsql.Benchmarks/TypeHandlers/Numeric.cs @@ -7,37 +7,37 @@ namespace Npgsql.Benchmarks.TypeHandlers [Config(typeof(Config))] public class Int16 : TypeHandlerBenchmarks { - public Int16() : base(new Int16Handler(GetPostgresType("smallint"))) { } + public Int16() : base(new Int16Handler { PostgresType = GetPostgresType("smallint") }) { } } [Config(typeof(Config))] public class Int32 : TypeHandlerBenchmarks { - public Int32() : base(new Int32Handler(GetPostgresType("integer"))) { } + public Int32() : base(new Int32Handler { PostgresType = GetPostgresType("integer") }) { } } [Config(typeof(Config))] public class Int64 : TypeHandlerBenchmarks { - public Int64() : base(new Int64Handler(GetPostgresType("bigint"))) { } + public Int64() : base(new Int64Handler { PostgresType = GetPostgresType("bigint") }) { } } [Config(typeof(Config))] public class Single : TypeHandlerBenchmarks { - public Single() : base(new SingleHandler(GetPostgresType("real"))) { } + public Single() : base(new SingleHandler { PostgresType = GetPostgresType("real") }) { } } [Config(typeof(Config))] public class Double : TypeHandlerBenchmarks { - public Double() : base(new DoubleHandler(GetPostgresType("double precision"))) { } + public Double() : base(new DoubleHandler { PostgresType = GetPostgresType("double precision") }) { } } [Config(typeof(Config))] public class Numeric : TypeHandlerBenchmarks { - public Numeric() : base(new NumericHandler(GetPostgresType("numeric"))) { } + public Numeric() : base(new NumericHandler { PostgresType = GetPostgresType("numeric") }) { } protected override IEnumerable ValuesOverride() => new[] { @@ -62,6 +62,6 @@ protected override IEnumerable ValuesOverride() => new[] [Config(typeof(Config))] public class Money : TypeHandlerBenchmarks { - public Money() : base(new MoneyHandler(GetPostgresType("money"))) { } + public Money() : base(new MoneyHandler { PostgresType = GetPostgresType("money") }) { } } } diff --git a/test/Npgsql.Benchmarks/TypeHandlers/Uuid.cs b/test/Npgsql.Benchmarks/TypeHandlers/Uuid.cs index 3743261c7f..1b3819b889 100644 --- a/test/Npgsql.Benchmarks/TypeHandlers/Uuid.cs +++ b/test/Npgsql.Benchmarks/TypeHandlers/Uuid.cs @@ -7,6 +7,6 @@ namespace Npgsql.Benchmarks.TypeHandlers [Config(typeof(Config))] public class Uuid : TypeHandlerBenchmarks { - public Uuid() : base(new UuidHandler(GetPostgresType("uuid"))) { } + public Uuid() : base(new UuidHandler { PostgresType = GetPostgresType("uuid") }) { } } } diff --git a/test/Npgsql.Tests/ReaderTests.cs b/test/Npgsql.Tests/ReaderTests.cs index 8a568d6c01..4983be3f91 100644 --- a/test/Npgsql.Tests/ReaderTests.cs +++ b/test/Npgsql.Tests/ReaderTests.cs @@ -2145,7 +2145,10 @@ class ExplodingTypeHandler : NpgsqlSimpleTypeHandler { readonly bool _safe; internal ExplodingTypeHandler(PostgresType postgresType, bool safe) - : base(postgresType) => _safe = safe; + { + PostgresType = postgresType; + _safe = safe; + } public override int Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null) { diff --git a/test/Npgsql.Tests/TypeMapperTests.cs b/test/Npgsql.Tests/TypeMapperTests.cs index 4f1266e43a..44a842aa7e 100644 --- a/test/Npgsql.Tests/TypeMapperTests.cs +++ b/test/Npgsql.Tests/TypeMapperTests.cs @@ -231,8 +231,8 @@ class MyInt32Handler : Int32Handler readonly MyInt32HandlerFactory _factory; public MyInt32Handler(PostgresType postgresType, MyInt32HandlerFactory factory) - : base(postgresType) { + PostgresType = postgresType; _factory = factory; } From a934b8d66cb9a165125dee2cf719e89f69dc203d Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Sun, 6 Jun 2021 18:34:09 +0200 Subject: [PATCH 2/3] Make DefaultTypeHandlerFactory sealed --- src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs index eb2359fa48..9640ad898e 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandlerFactory.cs @@ -56,7 +56,7 @@ public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlCo /// /// A type handler factory used to instantiate Npgsql's built-in type handlers. /// - class DefaultTypeHandlerFactory : NpgsqlTypeHandlerFactory + sealed class DefaultTypeHandlerFactory : NpgsqlTypeHandlerFactory where THandler : NpgsqlTypeHandler, new() { public override NpgsqlTypeHandler CreateNonGeneric(PostgresType pgType, NpgsqlConnector conn) From acf1902ab9e0815b721f54836435945e0535cffa Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Mon, 7 Jun 2021 10:43:57 +0200 Subject: [PATCH 3/3] Remove init property causing weird test failures --- src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs index e918dec0b8..712df54ce9 100644 --- a/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs +++ b/src/Npgsql/Internal/TypeHandling/NpgsqlTypeHandler.cs @@ -22,7 +22,7 @@ public abstract class NpgsqlTypeHandler /// /// The PostgreSQL type handled by this type handler. /// - public PostgresType PostgresType { get; init; } = null!; + public PostgresType PostgresType { get; set; } = null!; #region Read