Skip to content

Commit 2ae0b6a

Browse files
Added .NET 10 RC 2 and refactored some code for C# 14 (#2307)
1 parent 5ff0ada commit 2ae0b6a

File tree

68 files changed

+2081
-2197
lines changed

Some content is hidden

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

68 files changed

+2081
-2197
lines changed

.github/workflows/pull-request.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Upload
18-
uses: actions/upload-artifact@v4
18+
uses: actions/upload-artifact@v5
1919
with:
2020
name: Event File
2121
path: ${{ github.event_path }}
@@ -28,21 +28,28 @@ jobs:
2828
steps:
2929
-
3030
name: Checkout
31-
uses: actions/checkout@v4
31+
uses: actions/checkout@v5
3232
-
3333
name: Setup .NET
34-
uses: actions/setup-dotnet@v4
34+
uses: actions/setup-dotnet@v5
3535
with:
3636
dotnet-version: |
3737
8.0.x
3838
9.0.x
39+
-
40+
name: Setup .NET 10
41+
uses: actions/setup-dotnet@v5
42+
with:
43+
dotnet-version: |
44+
10.0.x
45+
dotnet-quality: 'preview'
3946
-
4047
name: Run tests
4148
run: dotnet test -c Debug -f ${{ matrix.dotnet }}
4249
-
4350
name: Upload Test Results
4451
if: always()
45-
uses: actions/upload-artifact@v4
52+
uses: actions/upload-artifact@v5
4653
with:
4754
name: Test Results Windows ${{ matrix.dotnet }}
4855
path: |
@@ -59,21 +66,28 @@ jobs:
5966
steps:
6067
-
6168
name: Checkout
62-
uses: actions/checkout@v4
69+
uses: actions/checkout@v5
6370
-
6471
name: Setup .NET
65-
uses: actions/setup-dotnet@v4
72+
uses: actions/setup-dotnet@v5
6673
with:
6774
dotnet-version: |
6875
8.0.x
6976
9.0.x
77+
-
78+
name: Setup .NET 10
79+
uses: actions/setup-dotnet@v5
80+
with:
81+
dotnet-version: |
82+
10.0.x
83+
dotnet-quality: 'preview'
7084
-
7185
name: Run tests
7286
run: dotnet test -f ${{ matrix.dotnet }}
7387
-
7488
name: Upload Test Results
7589
if: always()
76-
uses: actions/upload-artifact@v4
90+
uses: actions/upload-artifact@v5
7791
with:
7892
name: Test Results Ubuntu ${{ matrix.dotnet }}
7993
path: |

Directory.Packages.props

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
5-
<PropertyGroup Label="Package versions for .NET 8" Condition="$(TargetFramework) == 'net8.0'">
6-
<MicrosoftTestHostVer>8.0.3</MicrosoftTestHostVer>
5+
<PropertyGroup Label="Package versions for .NET 10" Condition="'$(TargetFramework)' == 'net10.0'">
6+
<MicrosoftTestHostVer>10.0.0-rc.2.25502.107</MicrosoftTestHostVer>
7+
<SystemTextJsonVer>10.0.0-rc.2.25502.107</SystemTextJsonVer>
78
</PropertyGroup>
8-
<PropertyGroup Label="Package versions for .NET 9" Condition="$(TargetFramework) == 'net9.0'">
9-
<MicrosoftTestHostVer>9.0.0</MicrosoftTestHostVer>
9+
<PropertyGroup Label="Package versions for .NET 9" Condition="'$(TargetFramework)' == 'net9.0'">
10+
<MicrosoftTestHostVer>9.0.10</MicrosoftTestHostVer>
11+
</PropertyGroup>
12+
<PropertyGroup Label="Package versions for .NET 8" Condition="'$(TargetFramework)' == 'net8.0'">
13+
<MicrosoftTestHostVer>8.0.21</MicrosoftTestHostVer>
14+
</PropertyGroup>
15+
<PropertyGroup Label="Package versions for pre-.NET 10" Condition="'$(TargetFramework)' != 'net10.0'">
16+
<SystemTextJsonVer>9.0.10</SystemTextJsonVer>
1017
</PropertyGroup>
1118
<ItemGroup Label="Runtime dependencies">
1219
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3"/>
1320
<PackageVersion Include="CsvHelper" Version="33.0.1"/>
14-
<PackageVersion Include="System.Text.Json" Version="9.0.0"/>
21+
<PackageVersion Include="System.Text.Json" Version="$(SystemTextJsonVer)"/>
1522
</ItemGroup>
1623
<ItemGroup Label="Compile dependencies">
1724
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0"/>

benchmarks/RestSharp.Benchmarks/Requests/AddObjectToRequestParametersBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void GlobalSetup() {
2020
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
2121
var dateTime = DateTime.Parse("01/01/2013 03:03:12");
2222

23-
_data = new Data(@string, int.MaxValue, strings, ints, dateTime, strings);
23+
_data = new(@string, int.MaxValue, strings, ints, dateTime, strings);
2424
}
2525

2626
[Benchmark(Baseline = true)]

gen/SourceGenerator/Extensions.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
namespace SourceGenerator;
1616

1717
static class Extensions {
18-
public static IEnumerable<ClassDeclarationSyntax> FindClasses(this Compilation compilation, Func<ClassDeclarationSyntax, bool> predicate)
19-
=> compilation.SyntaxTrees
20-
.Select(tree => compilation.GetSemanticModel(tree))
21-
.SelectMany(model => model.SyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>())
22-
.Where(predicate);
18+
extension(Compilation compilation) {
19+
public IEnumerable<ClassDeclarationSyntax> FindClasses(Func<ClassDeclarationSyntax, bool> predicate)
20+
=> compilation.SyntaxTrees
21+
.Select(tree => compilation.GetSemanticModel(tree))
22+
.SelectMany(model => model.SyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>())
23+
.Where(predicate);
2324

24-
public static IEnumerable<ClassDeclarationSyntax> FindAnnotatedClasses(this Compilation compilation, string attributeName, bool strict) {
25-
return compilation.FindClasses(
26-
syntax => syntax.AttributeLists.Any(list => list.Attributes.Any(CheckAttribute))
27-
);
25+
public IEnumerable<ClassDeclarationSyntax> FindAnnotatedClasses(string attributeName, bool strict) {
26+
return compilation.FindClasses(
27+
syntax => syntax.AttributeLists.Any(list => list.Attributes.Any(CheckAttribute))
28+
);
2829

29-
bool CheckAttribute(AttributeSyntax attr) {
30-
var name = attr.Name.ToString();
31-
return strict ? name == attributeName : name.StartsWith(attributeName);
30+
bool CheckAttribute(AttributeSyntax attr) {
31+
var name = attr.Name.ToString();
32+
return strict ? name == attributeName : name.StartsWith(attributeName);
33+
}
3234
}
3335
}
3436

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'RestSharp.sln'))\props\Common.props"/>
33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net471;net48;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net471;net48;net8.0;net9.0;net10.0</TargetFrameworks>
55
<PackageIcon>restsharp.png</PackageIcon>
66
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
77
<PackageProjectUrl>https://restsharp.dev</PackageProjectUrl>

src/RestSharp.Serializers.CsvHelper/CsvHelperSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CsvHelperSerializer(CsvConfiguration configuration) : IDeserializer
1818

1919
public ContentType ContentType { get; set; } = ContentType.Csv;
2020

21-
public CsvHelperSerializer() : this(new CsvConfiguration(CultureInfo.InvariantCulture)) { }
21+
public CsvHelperSerializer() : this(new(CultureInfo.InvariantCulture)) { }
2222

2323
public T? Deserialize<T>(RestResponse response) {
2424
try {

src/RestSharp.Serializers.CsvHelper/RestClientExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ namespace RestSharp.Serializers.CsvHelper;
44

55
[PublicAPI]
66
public static class RestClientExtensions {
7-
public static SerializerConfig UseCsvHelper(this SerializerConfig config) => config.UseSerializer<CsvHelperSerializer>();
7+
extension(SerializerConfig config) {
8+
public SerializerConfig UseCsvHelper() => config.UseSerializer<CsvHelperSerializer>();
89

9-
public static SerializerConfig UseCsvHelper(this SerializerConfig config, CsvConfiguration configuration)
10-
=> config.UseSerializer(() => new CsvHelperSerializer(configuration));
10+
public SerializerConfig UseCsvHelper(CsvConfiguration configuration)
11+
=> config.UseSerializer(() => new CsvHelperSerializer(configuration));
12+
}
1113
}

src/RestSharp.Serializers.NewtonsoftJson/JsonNetSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class JsonNetSerializer : IRestSerializer, ISerializer, IDeserializer {
5252
public string? Serialize(object? obj) {
5353
if (obj == null) return null;
5454

55-
using var buffer = _writerBuffer ??= new WriterBuffer(_serializer);
55+
using var buffer = _writerBuffer ??= new(_serializer);
5656

5757
_serializer.Serialize(buffer.GetJsonTextWriter(), obj, obj.GetType());
5858

src/RestSharp.Serializers.NewtonsoftJson/RestClientExtensions.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ namespace RestSharp.Serializers.NewtonsoftJson;
1616

1717
[PublicAPI]
1818
public static class RestClientExtensions {
19-
/// <summary>
20-
/// Use Newtonsoft.Json serializer with default settings
21-
/// </summary>
2219
/// <param name="config"></param>
23-
/// <returns></returns>
24-
public static SerializerConfig UseNewtonsoftJson(this SerializerConfig config) => config.UseSerializer(() => new JsonNetSerializer());
20+
extension(SerializerConfig config) {
21+
/// <summary>
22+
/// Use Newtonsoft.Json serializer with default settings
23+
/// </summary>
24+
/// <returns></returns>
25+
public SerializerConfig UseNewtonsoftJson() => config.UseSerializer(() => new JsonNetSerializer());
2526

26-
/// <summary>
27-
/// Use Newtonsoft.Json serializer with custom settings
28-
/// </summary>
29-
/// <param name="config"></param>
30-
/// <param name="settings">Newtonsoft.Json serializer settings</param>
31-
/// <returns></returns>
32-
public static SerializerConfig UseNewtonsoftJson(this SerializerConfig config, JsonSerializerSettings settings)
33-
=> config.UseSerializer(() => new JsonNetSerializer(settings));
27+
/// <summary>
28+
/// Use Newtonsoft.Json serializer with custom settings
29+
/// </summary>
30+
/// <param name="settings">Newtonsoft.Json serializer settings</param>
31+
/// <returns></returns>
32+
public SerializerConfig UseNewtonsoftJson(JsonSerializerSettings settings)
33+
=> config.UseSerializer(() => new JsonNetSerializer(settings));
34+
}
3435
}

src/RestSharp.Serializers.NewtonsoftJson/WriterBuffer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
using System.Globalization;
16-
using System.Text;
1716

1817
namespace RestSharp.Serializers.NewtonsoftJson;
1918

@@ -22,9 +21,9 @@ sealed class WriterBuffer : IDisposable {
2221
readonly JsonTextWriter _jsonTextWriter;
2322

2423
public WriterBuffer(JsonSerializer jsonSerializer) {
25-
_stringWriter = new StringWriter(new StringBuilder(256), CultureInfo.InvariantCulture);
24+
_stringWriter = new(new(256), CultureInfo.InvariantCulture);
2625

27-
_jsonTextWriter = new JsonTextWriter(_stringWriter) {
26+
_jsonTextWriter = new(_stringWriter) {
2827
Formatting = jsonSerializer.Formatting, CloseOutput = false
2928
};
3029
}

0 commit comments

Comments
 (0)