Skip to content

Commit f8fd671

Browse files
committed
Upgrade to .NET 7 and C# 11
1 parent c937af7 commit f8fd671

File tree

65 files changed

+1748
-1239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1748
-1239
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
with:
3939
dotnet-version: |
4040
3.1.x
41-
5.0.x
41+
6.0.x
4242
global-json-file: "./global.json"
4343
- name: "Dotnet Tool Restore"
4444
run: dotnet tool restore

Benchmarks/Schema.NET.Benchmarks/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ namespace Schema.NET.Benchmarks;
44

55
public class Program
66
{
7-
private static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
7+
private static void Main(string[] args) =>
8+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
89
}

Benchmarks/Schema.NET.Benchmarks/Schema.NET.Benchmarks.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup Label="Build">
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net6.0;net5.0;net472</TargetFrameworks>
5+
<TargetFrameworks>net7.0;net6.0;net472</TargetFrameworks>
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup Label="Build">
4-
<LangVersion>latest</LangVersion>
4+
<LangVersion>preview</LangVersion>
55
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
66
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
77
<AnalysisLevel>latest</AnalysisLevel>

Source/Common/DateTimeToIso8601DateValuesJsonConverter.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Schema.NET;
1313
/// <seealso cref="ValuesJsonConverter" />
1414
public class DateTimeToIso8601DateValuesJsonConverter : ValuesJsonConverter
1515
{
16+
private const string DateFormat = "yyyy-MM-dd";
17+
1618
/// <summary>
1719
/// Writes the object retrieved from <see cref="IValues" /> when one is found.
1820
/// </summary>
@@ -38,7 +40,7 @@ public override void WriteObject(Utf8JsonWriter writer, object? value, JsonSeria
3840

3941
if (value is DateTime dateTimeType)
4042
{
41-
writer.WriteStringValue(dateTimeType.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
43+
writer.WriteStringValue(dateTimeType.ToString(DateFormat, CultureInfo.InvariantCulture));
4244
}
4345
else
4446
{

Source/Common/FastActivator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ internal static class FastActivator
3535
}
3636

3737
private static Func<T1, object> CreateConstructorDelegate<T1>(ConstructorInfo constructor) => Expression.Lambda<Func<T1, object>>(
38-
Expression.Convert(
39-
Expression.New(constructor, ConstructorParameter<T1>.SingleParameter),
40-
typeof(object)),
41-
ConstructorParameter<T1>.SingleParameter).Compile();
38+
Expression.Convert(
39+
Expression.New(constructor, ConstructorParameter<T1>.SingleParameter),
40+
typeof(object)),
41+
ConstructorParameter<T1>.SingleParameter).Compile();
4242

4343
private static ConstructorInfo? GetConstructorInfo(Type objectType, Type parameter1)
4444
{

Source/Common/HashCode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public override bool Equals(object? obj)
114114
[EditorBrowsable(EditorBrowsableState.Never)]
115115
public override int GetHashCode() =>
116116
#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
117-
throw new NotSupportedException("Implicitly convert this struct to an int to get the hash code.");
117+
throw new NotSupportedException("Implicitly convert this struct to an int to get the hash code.");
118118
#pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
119119

120120
private static int CombineHashCodes(int h1, int h2)

Source/Common/PropertyValueSpecification.Partial.cs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace Schema.NET;
22

3-
using System.Collections.Generic;
43
using System.Linq;
54
using System.Text;
65

@@ -9,6 +8,13 @@ namespace Schema.NET;
98
/// </summary>
109
public partial class PropertyValueSpecification
1110
{
11+
private const string MaxLengthPropertyName = "maxlength=";
12+
private const string MinLengthPropertyName = "minlength=";
13+
private const string NamePropertyName = "name=";
14+
private const string PatternPropertyName = "pattern=";
15+
private const string RequiredPropertyName = "required";
16+
private const char Space = ' ';
17+
1218
/// <summary>
1319
/// Returns a <see cref="string" /> that represents the short hand representation of this instance.
1420
/// See https://schema.org/docs/actions.html#part-3.
@@ -22,35 +28,35 @@ public override string ToString()
2228

2329
if (this.ValueMaxLength.First() is double maxLength)
2430
{
25-
stringBuilder.Append("maxlength=");
31+
stringBuilder.Append(MaxLengthPropertyName);
2632
stringBuilder.Append(maxLength);
2733
}
2834

2935
if (this.ValueMinLength.First() is double minLength)
3036
{
3137
AppendSpace(stringBuilder);
32-
stringBuilder.Append("minlength=");
38+
stringBuilder.Append(MinLengthPropertyName);
3339
stringBuilder.Append(minLength);
3440
}
3541

3642
if (this.ValueName.First() is string name)
3743
{
3844
AppendSpace(stringBuilder);
39-
stringBuilder.Append("name=");
45+
stringBuilder.Append(NamePropertyName);
4046
stringBuilder.Append(name);
4147
}
4248

4349
if (this.ValuePattern.First() is string pattern)
4450
{
4551
AppendSpace(stringBuilder);
46-
stringBuilder.Append("pattern=");
52+
stringBuilder.Append(PatternPropertyName);
4753
stringBuilder.Append(pattern);
4854
}
4955

5056
if (this.ValueRequired.First() is true)
5157
{
5258
AppendSpace(stringBuilder);
53-
stringBuilder.Append("required");
59+
stringBuilder.Append(RequiredPropertyName);
5460
}
5561

5662
return stringBuilder.ToString();
@@ -60,7 +66,7 @@ private static void AppendSpace(StringBuilder stringBuilder)
6066
{
6167
if (stringBuilder.Length > 0)
6268
{
63-
stringBuilder.Append(' ');
69+
stringBuilder.Append(Space);
6470
}
6571
}
6672
}

Source/Common/SchemaEnumJsonConverter{T}.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Schema.NET;
1010
/// <summary>
1111
/// Converts a Schema enumeration to and from JSON.
1212
/// </summary>
13-
/// <typeparam name="T">The enum type to convert</typeparam>
13+
/// <typeparam name="T">The enumeration type to convert.</typeparam>
1414
public class SchemaEnumJsonConverter<T> : JsonConverter<T>
1515
where T : struct, Enum
1616
{
@@ -41,11 +41,21 @@ public SchemaEnumJsonConverter()
4141
/// <returns>The enumeration value.</returns>
4242
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
4343
{
44+
#if NET6_0_OR_GREATER
45+
ArgumentNullException.ThrowIfNull(typeToConvert);
46+
ArgumentNullException.ThrowIfNull(options);
47+
#else
4448
if (typeToConvert is null)
4549
{
4650
throw new ArgumentNullException(nameof(typeToConvert));
4751
}
4852

53+
if (options is null)
54+
{
55+
throw new ArgumentNullException(nameof(options));
56+
}
57+
#endif
58+
4959
var valueString = reader.GetString();
5060
if (EnumHelper.TryParseEnumFromSchemaUri(typeToConvert, valueString, out var result))
5161
{
@@ -63,11 +73,21 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
6373
/// <param name="options">The JSON serializer options.</param>
6474
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
6575
{
76+
#if NET6_0_OR_GREATER
77+
ArgumentNullException.ThrowIfNull(writer);
78+
ArgumentNullException.ThrowIfNull(options);
79+
#else
6680
if (writer is null)
6781
{
6882
throw new ArgumentNullException(nameof(writer));
6983
}
7084

85+
if (options is null)
86+
{
87+
throw new ArgumentNullException(nameof(options));
88+
}
89+
#endif
90+
7191
writer.WriteStringValue(this.valueNameMap[value]);
7292
}
7393
}

Source/Common/SchemaSerializer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace Schema.NET;
22

33
using System;
4-
using System.Collections.Generic;
54
using System.Text;
5+
using System.Text.Encodings.Web;
66
using System.Text.Json;
77
using System.Text.Json.Serialization;
88

@@ -32,7 +32,7 @@ static SchemaSerializer()
3232
{
3333
AllowTrailingCommas = true,
3434
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
35-
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
35+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
3636
};
3737

3838
HtmlEscapedSerializationSettings = new JsonSerializerOptions

Source/Common/Values{T1,T2,T3,T4,T5,T6,T7}.cs

-7
Original file line numberDiff line numberDiff line change
@@ -209,43 +209,36 @@ public Values(IEnumerable<object?> items)
209209
if (item is T7 itemT7)
210210
{
211211
items7 ??= new List<T7>();
212-
213212
items7.Add(itemT7);
214213
}
215214
else if (item is T6 itemT6)
216215
{
217216
items6 ??= new List<T6>();
218-
219217
items6.Add(itemT6);
220218
}
221219
else if (item is T5 itemT5)
222220
{
223221
items5 ??= new List<T5>();
224-
225222
items5.Add(itemT5);
226223
}
227224
else if (item is T4 itemT4)
228225
{
229226
items4 ??= new List<T4>();
230-
231227
items4.Add(itemT4);
232228
}
233229
else if (item is T3 itemT3)
234230
{
235231
items3 ??= new List<T3>();
236-
237232
items3.Add(itemT3);
238233
}
239234
else if (item is T2 itemT2)
240235
{
241236
items2 ??= new List<T2>();
242-
243237
items2.Add(itemT2);
244238
}
245239
else if (item is T1 itemT1)
246240
{
247241
items1 ??= new List<T1>();
248-
249242
items1.Add(itemT1);
250243
}
251244
}

Source/Common/Values{T1,T2,T3,T4,T5,T6}.cs

-6
Original file line numberDiff line numberDiff line change
@@ -173,37 +173,31 @@ public Values(IEnumerable<object?> items)
173173
if (item is T6 itemT6)
174174
{
175175
items6 ??= new List<T6>();
176-
177176
items6.Add(itemT6);
178177
}
179178
else if (item is T5 itemT5)
180179
{
181180
items5 ??= new List<T5>();
182-
183181
items5.Add(itemT5);
184182
}
185183
else if (item is T4 itemT4)
186184
{
187185
items4 ??= new List<T4>();
188-
189186
items4.Add(itemT4);
190187
}
191188
else if (item is T3 itemT3)
192189
{
193190
items3 ??= new List<T3>();
194-
195191
items3.Add(itemT3);
196192
}
197193
else if (item is T2 itemT2)
198194
{
199195
items2 ??= new List<T2>();
200-
201196
items2.Add(itemT2);
202197
}
203198
else if (item is T1 itemT1)
204199
{
205200
items1 ??= new List<T1>();
206-
207201
items1.Add(itemT1);
208202
}
209203
}

Source/Common/Values{T1,T2,T3,T4}.cs

-4
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,21 @@ public Values(IEnumerable<object?> items)
113113
if (item is T4 itemT4)
114114
{
115115
items4 ??= new List<T4>();
116-
117116
items4.Add(itemT4);
118117
}
119118
else if (item is T3 itemT3)
120119
{
121120
items3 ??= new List<T3>();
122-
123121
items3.Add(itemT3);
124122
}
125123
else if (item is T2 itemT2)
126124
{
127125
items2 ??= new List<T2>();
128-
129126
items2.Add(itemT2);
130127
}
131128
else if (item is T1 itemT1)
132129
{
133130
items1 ??= new List<T1>();
134-
135131
items1.Add(itemT1);
136132
}
137133
}

Source/Common/Values{T1,T2,T3}.cs

-3
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,16 @@ public Values(IEnumerable<object> items)
8989
if (item is T3 itemT3)
9090
{
9191
items3 ??= new List<T3>();
92-
9392
items3.Add(itemT3);
9493
}
9594
else if (item is T2 itemT2)
9695
{
9796
items2 ??= new List<T2>();
98-
9997
items2.Add(itemT2);
10098
}
10199
else if (item is T1 itemT1)
102100
{
103101
items1 ??= new List<T1>();
104-
105102
items1.Add(itemT1);
106103
}
107104
}

Source/Common/Values{T1,T2}.cs

-6
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ public Values(IEnumerable<object?> items)
6969
if (item is T2 itemT2)
7070
{
7171
items2 ??= new List<T2>();
72-
7372
items2.Add(itemT2);
7473
}
7574
else if (item is T1 itemT1)
7675
{
7776
items1 ??= new List<T1>();
78-
7977
items1.Add(itemT1);
8078
}
8179
}
@@ -117,8 +115,6 @@ public Values(IEnumerable<object?> items)
117115
/// </summary>
118116
public OneOrMany<T2> Value2 { get; }
119117

120-
#pragma warning disable CA1002 // Do not expose generic lists
121-
#pragma warning disable CA2225 // Operator overloads have named alternates
122118
/// <summary>
123119
/// Performs an implicit conversion from <typeparamref name="T1"/> to <see cref="Values{T1,T2}"/>.
124120
/// </summary>
@@ -228,8 +224,6 @@ public Values(IEnumerable<object?> items)
228224
/// The result of the conversion.
229225
/// </returns>
230226
public static implicit operator List<T2>(Values<T1, T2> values) => values.Value2.ToList();
231-
#pragma warning restore CA2225 // Operator overloads have named alternates
232-
#pragma warning restore CA1002 // Do not expose generic lists
233227

234228
/// <summary>
235229
/// Implements the operator ==.

Source/Schema.NET.Pending/Schema.NET.Pending.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup Label="Build">
4-
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
4+
<TargetFrameworks>net7.0;net6.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
55
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
66
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
77
<IncludePendingSchemaObjects>True</IncludePendingSchemaObjects>

Source/Schema.NET/Schema.NET.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup Label="Build">
4-
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
4+
<TargetFrameworks>net7.0;net6.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
55
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
66
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
77
<IncludePendingSchemaObjects>False</IncludePendingSchemaObjects>

0 commit comments

Comments
 (0)