Skip to content

Commit 557e166

Browse files
committed
Make Npgsql-specific JsonValueReaderWriters public for compiled model (#3029)
Fixes #2972 (cherry picked from commit adff7ad)
1 parent 07f00f8 commit 557e166

11 files changed

+319
-15
lines changed

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlBigIntegerTypeMapping.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,38 @@ protected override string ProcessStoreType(RelationalTypeMappingParameters param
6464
? $"numeric({parameters.Precision})"
6565
: $"numeric({parameters.Precision},{parameters.Scale})";
6666

67-
private sealed class JsonBigIntegerReaderWriter : JsonValueReaderWriter<BigInteger>
67+
/// <summary>
68+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
69+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
70+
/// any release. You should only use it directly in your code with extreme caution and knowing that
71+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
72+
/// </summary>
73+
public sealed class JsonBigIntegerReaderWriter : JsonValueReaderWriter<BigInteger>
6874
{
75+
/// <summary>
76+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
77+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
78+
/// any release. You should only use it directly in your code with extreme caution and knowing that
79+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
80+
/// </summary>
6981
public static JsonBigIntegerReaderWriter Instance { get; } = new();
7082

83+
/// <summary>
84+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
85+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
86+
/// any release. You should only use it directly in your code with extreme caution and knowing that
87+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
88+
/// </summary>
7189
// Other systems handling the JSON very likely won't support arbitrary-length numbers here, we encode as a string
7290
public override BigInteger FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
7391
=> BigInteger.Parse(manager.CurrentReader.GetString()!);
7492

93+
/// <summary>
94+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
95+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
96+
/// any release. You should only use it directly in your code with extreme caution and knowing that
97+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
98+
/// </summary>
7599
public override void ToJsonTyped(Utf8JsonWriter writer, BigInteger value)
76100
=> writer.WriteStringValue(value.ToString());
77101
}

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlCidrTypeMapping.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,37 @@ public override Expression GenerateCodeLiteral(object value)
8383
private static readonly ConstructorInfo NpgsqlCidrConstructor =
8484
typeof(NpgsqlCidr).GetConstructor(new[] { typeof(IPAddress), typeof(byte) })!;
8585

86-
private sealed class JsonCidrReaderWriter : JsonValueReaderWriter<NpgsqlCidr>
86+
/// <summary>
87+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
88+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
89+
/// any release. You should only use it directly in your code with extreme caution and knowing that
90+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
91+
/// </summary>
92+
public sealed class JsonCidrReaderWriter : JsonValueReaderWriter<NpgsqlCidr>
8793
{
94+
/// <summary>
95+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
96+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
97+
/// any release. You should only use it directly in your code with extreme caution and knowing that
98+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
99+
/// </summary>
88100
public static JsonCidrReaderWriter Instance { get; } = new();
89101

102+
/// <summary>
103+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
104+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
105+
/// any release. You should only use it directly in your code with extreme caution and knowing that
106+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
107+
/// </summary>
90108
public override NpgsqlCidr FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
91109
=> new(manager.CurrentReader.GetString()!);
92110

111+
/// <summary>
112+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
113+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
114+
/// any release. You should only use it directly in your code with extreme caution and knowing that
115+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
116+
/// </summary>
93117
public override void ToJsonTyped(Utf8JsonWriter writer, NpgsqlCidr value)
94118
=> writer.WriteStringValue(value.ToString());
95119
}

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlDateOnlyTypeMapping.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,28 @@ private static string Format(DateOnly date)
8787
return date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
8888
}
8989

90-
private sealed class NpgsqlJsonDateOnlyReaderWriter : JsonValueReaderWriter<DateOnly>
90+
/// <summary>
91+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
92+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
93+
/// any release. You should only use it directly in your code with extreme caution and knowing that
94+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
95+
/// </summary>
96+
public sealed class NpgsqlJsonDateOnlyReaderWriter : JsonValueReaderWriter<DateOnly>
9197
{
98+
/// <summary>
99+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
100+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
101+
/// any release. You should only use it directly in your code with extreme caution and knowing that
102+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
103+
/// </summary>
92104
public static NpgsqlJsonDateOnlyReaderWriter Instance { get; } = new();
93105

106+
/// <summary>
107+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
108+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
109+
/// any release. You should only use it directly in your code with extreme caution and knowing that
110+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
111+
/// </summary>
94112
public override DateOnly FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
95113
{
96114
var s = manager.CurrentReader.GetString()!;
@@ -109,6 +127,12 @@ public override DateOnly FromJsonTyped(ref Utf8JsonReaderManager manager, object
109127
return DateOnly.Parse(s, CultureInfo.InvariantCulture);
110128
}
111129

130+
/// <summary>
131+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
132+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
133+
/// any release. You should only use it directly in your code with extreme caution and knowing that
134+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
135+
/// </summary>
112136
public override void ToJsonTyped(Utf8JsonWriter writer, DateOnly value)
113137
=> writer.WriteStringValue(Format(value));
114138
}

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlDateTimeDateTypeMapping.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,28 @@ private static string Format(DateTime date)
8787
return date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
8888
}
8989

90-
private sealed class NpgsqlJsonDateTimeReaderWriter : JsonValueReaderWriter<DateTime>
90+
/// <summary>
91+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
92+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
93+
/// any release. You should only use it directly in your code with extreme caution and knowing that
94+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
95+
/// </summary>
96+
public sealed class NpgsqlJsonDateTimeReaderWriter : JsonValueReaderWriter<DateTime>
9197
{
98+
/// <summary>
99+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
100+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
101+
/// any release. You should only use it directly in your code with extreme caution and knowing that
102+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
103+
/// </summary>
92104
public static NpgsqlJsonDateTimeReaderWriter Instance { get; } = new();
93105

106+
/// <summary>
107+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
108+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
109+
/// any release. You should only use it directly in your code with extreme caution and knowing that
110+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
111+
/// </summary>
94112
public override DateTime FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
95113
{
96114
var s = manager.CurrentReader.GetString()!;
@@ -109,6 +127,12 @@ public override DateTime FromJsonTyped(ref Utf8JsonReaderManager manager, object
109127
return DateTime.Parse(s, CultureInfo.InvariantCulture);
110128
}
111129

130+
/// <summary>
131+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
132+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
133+
/// any release. You should only use it directly in your code with extreme caution and knowing that
134+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
135+
/// </summary>
112136
public override void ToJsonTyped(Utf8JsonWriter writer, DateTime value)
113137
=> writer.WriteStringValue(Format(value));
114138
}

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlInetTypeMapping.cs

+50-2
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,72 @@ public override Expression GenerateCodeLiteral(object value)
8585
private static readonly MethodInfo IPAddressParseMethod = typeof(IPAddress).GetMethod("Parse", new[] { typeof(string) })!;
8686
private static readonly ConstructorInfo NpgsqlInetConstructor = typeof(NpgsqlInet).GetConstructor(new[] { typeof(string) })!;
8787

88-
private sealed class JsonIPAddressReaderWriter : JsonValueReaderWriter<IPAddress>
88+
/// <summary>
89+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
90+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
91+
/// any release. You should only use it directly in your code with extreme caution and knowing that
92+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
93+
/// </summary>
94+
public sealed class JsonIPAddressReaderWriter : JsonValueReaderWriter<IPAddress>
8995
{
96+
/// <summary>
97+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
98+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
99+
/// any release. You should only use it directly in your code with extreme caution and knowing that
100+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
101+
/// </summary>
90102
public static JsonIPAddressReaderWriter Instance { get; } = new();
91103

104+
/// <summary>
105+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
106+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
107+
/// any release. You should only use it directly in your code with extreme caution and knowing that
108+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
109+
/// </summary>
92110
public override IPAddress FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
93111
=> IPAddress.Parse(manager.CurrentReader.GetString()!);
94112

113+
/// <summary>
114+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
115+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
116+
/// any release. You should only use it directly in your code with extreme caution and knowing that
117+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
118+
/// </summary>
95119
public override void ToJsonTyped(Utf8JsonWriter writer, IPAddress value)
96120
=> writer.WriteStringValue(value.ToString());
97121
}
98122

99-
private sealed class JsonNpgsqlInetReaderWriter : JsonValueReaderWriter<NpgsqlInet>
123+
/// <summary>
124+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
125+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
126+
/// any release. You should only use it directly in your code with extreme caution and knowing that
127+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
128+
/// </summary>
129+
public sealed class JsonNpgsqlInetReaderWriter : JsonValueReaderWriter<NpgsqlInet>
100130
{
131+
/// <summary>
132+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
133+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
134+
/// any release. You should only use it directly in your code with extreme caution and knowing that
135+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
136+
/// </summary>
101137
public static JsonNpgsqlInetReaderWriter Instance { get; } = new();
102138

139+
/// <summary>
140+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
141+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
142+
/// any release. You should only use it directly in your code with extreme caution and knowing that
143+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
144+
/// </summary>
103145
public override NpgsqlInet FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
104146
=> new(manager.CurrentReader.GetString()!);
105147

148+
/// <summary>
149+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
150+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
151+
/// any release. You should only use it directly in your code with extreme caution and knowing that
152+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
153+
/// </summary>
106154
public override void ToJsonTyped(Utf8JsonWriter writer, NpgsqlInet value)
107155
=> writer.WriteStringValue(value.ToString());
108156
}

src/EFCore.PG/Storage/Internal/Mapping/NpgsqlIntervalTypeMapping.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,37 @@ public static TimeSpan ParseIntervalAsTimeSpan(ReadOnlySpan<char> s)
155155
return timeSpan;
156156
}
157157

158-
private sealed class NpgsqlJsonTimeSpanReaderWriter : JsonValueReaderWriter<TimeSpan>
158+
/// <summary>
159+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
160+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
161+
/// any release. You should only use it directly in your code with extreme caution and knowing that
162+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
163+
/// </summary>
164+
public sealed class NpgsqlJsonTimeSpanReaderWriter : JsonValueReaderWriter<TimeSpan>
159165
{
166+
/// <summary>
167+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
168+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
169+
/// any release. You should only use it directly in your code with extreme caution and knowing that
170+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
171+
/// </summary>
160172
public static NpgsqlJsonTimeSpanReaderWriter Instance { get; } = new();
161173

174+
/// <summary>
175+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
176+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
177+
/// any release. You should only use it directly in your code with extreme caution and knowing that
178+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
179+
/// </summary>
162180
public override TimeSpan FromJsonTyped(ref Utf8JsonReaderManager manager, object? existingObject = null)
163181
=> ParseIntervalAsTimeSpan(manager.CurrentReader.GetString()!);
164182

183+
/// <summary>
184+
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
185+
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
186+
/// any release. You should only use it directly in your code with extreme caution and knowing that
187+
/// doing so can result in application failures when updating to a new Entity Framework Core release.
188+
/// </summary>
165189
public override void ToJsonTyped(Utf8JsonWriter writer, TimeSpan value)
166190
=> writer.WriteStringValue(FormatTimeSpanAsInterval(value));
167191
}

0 commit comments

Comments
 (0)