Added .NET 10 RC 2 and refactored some code for C# 14#2307
Conversation
PR Compliance Guide 🔍(Compliance updated until commit 109ab58)Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label Previous compliance checksCompliance check up to commit 109ab58
|
||||||||||||||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||||||||||
Test Results 25 files 25 suites 10m 52s ⏱️ Results for commit 109ab58. |
User description
Description
Add .NET target
PR Type
Enhancement
Description
Comprehensive refactoring to C# 14 and C# 13 modern syntax across the entire codebase
Converted all extension methods from static methods to C# 14
extensionsyntax with extension blocksUpdated object instantiation throughout to use target-typed
new()expressions for cleaner codeRefactored classes to use C# 14 primary constructor syntax where applicable
Applied C# 13
fieldkeyword for automatic backing field management in propertiesModernized test files with target-typed new expressions and improved assertions
Added .NET 10 RC 2 support to CI/CD pipeline with GitHub Actions v5
Updated GitHub Actions workflow to test against .NET 10 on both Windows and Ubuntu runners
Minor bug fix: Added null-safety check for URL property access in test fixtures
Diagram Walkthrough
File Walkthrough
62 files
XmlDeserializerTests.cs
C# 14 modernization with target-typed new expressionstest/RestSharp.Tests.Serializers.Xml/XmlDeserializerTests.cs
new RestResponse { Content = ... }with target-typednew() { Content = ... }syntax (C# 9 feature)new DateTime(...)andnew TimeSpan(...)to target-typednew(...)syntaxnew Guid(...)andnew Uri(...)to target-typednew(...)syntaxAssert.False(x == 0)withAssert.NotEqual(0, x)for clearertest assertions
RestClient.Extensions.Get.cs
Refactored to C# 11 extension method syntaxsrc/RestSharp/RestClient.Extensions.Get.cs
using C# 11 extension syntax
extension(IRestClient client)blockthiskeyword andIRestClient clientparameter from methodsignatures
clientparameter referencesnew RestRequest(resource)to target-typednew(resource)syntaxRestClient.Extensions.Delete.cs
Refactored to C# 11 extension method syntaxsrc/RestSharp/RestClient.Extensions.Delete.cs
using C# 11 extension syntax
extension(IRestClient client)blockthiskeyword andIRestClient clientparameter from methodsignatures
clientparameter referencesRestClient.Extensions.Put.cs
Refactored to C# 11 extension method syntaxsrc/RestSharp/RestClient.Extensions.Put.cs
using C# 11 extension syntax
extension(IRestClient client)blockthiskeyword andIRestClient clientparameter from methodsignatures
clientparameter referencesRestClient.Extensions.Post.cs
Refactored to C# 11 extension method syntaxsrc/RestSharp/RestClient.Extensions.Post.cs
using C# 11 extension syntax
extension(IRestClient client)blockthiskeyword andIRestClient clientparameter from methodsignatures
clientparameter referencesXmlAttributeDeserializerTests.cs
C# 14 modernization with target-typed new expressionstest/RestSharp.Tests.Serializers.Xml/XmlAttributeDeserializerTests.cs
new RestResponse { Content = ... }with target-typednew() { Content = ... }syntaxnew DateTime(...),new TimeSpan(...),new Guid(...), andnewUri(...)to target-typednew(...)syntaxAssert.False(x == 0)withAssert.NotEqual(0, x)for clearertest assertions
RestClient.Extensions.cs
Refactored to C# 11 extension method syntaxsrc/RestSharp/RestClient.Extensions.cs
using C# 11 extension syntax
extension(IRestClient client)blockthiskeyword andIRestClient clientparameter from methodsignatures
clientparameter referencesOAuthWorkflow.cs
C# 14 modernization with target-typed new expressionssrc/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs
new OAuthParameters { ... }to target-typednew() { ... }syntax
new WebPair(...)to target-typednew(...)syntax in collectioninitializer
urivariable declarationWriterBuffer.cs
C# 14 modernization and cleanupsrc/RestSharp.Serializers.NewtonsoftJson/WriterBuffer.cs
using System.Text;directivenew StringWriter(new StringBuilder(256), ...)to target-typednew(new(256), ...)syntaxnew JsonTextWriter(_stringWriter)to target-typednew(_stringWriter)syntaxRestRequestExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Request/RestRequestExtensions.cs
extension(RestRequest request)blocksthiskeyword andstaticmodifiers from methods withinextension blocks
requestparameterreferences
new CookieContainer()tonew()using target-typed newexpressions
StringExtensions.cs
Refactor string extensions to C# 14 syntaxsrc/RestSharp/Extensions/StringExtensions.cs
extension(stringinput)syntaxthiskeyword andstaticmodifiers from methods withinextension blocks
organization
RestRequestExtensions.Body.cs
Convert body extensions to C# 14 syntaxsrc/RestSharp/Request/RestRequestExtensions.Body.cs
extension(RestRequest request)syntaxthisandstatickeywords from method signaturesrequestparameterentries
RestClient.Extensions.Patch.cs
Refactor PATCH client extensions to C# 14src/RestSharp/RestClient.Extensions.Patch.cs
extension(IRestClient client)syntaxthisandstaticmodifiers from all extension methodsclientparameterreferences
RestClient.Extensions.Head.cs
Refactor HEAD client extensions to C# 14src/RestSharp/RestClient.Extensions.Head.cs
extension(IRestClientclient)syntaxthisandstatickeywords from method declarationsRestClient.Extensions.Options.cs
Refactor OPTIONS client extensions to C# 14src/RestSharp/RestClient.Extensions.Options.cs
extension(IRestClient client)syntaxthisandstaticmodifiers from extension methodsclientparameter entriesRestClient.Extensions.Params.cs
Refactor parameter client extensions to C# 14src/RestSharp/RestClient.Extensions.Params.cs
extension(IRestClient client)syntaxthisandstatickeywords from all methodsclientparameterreferences
XmlSerializerTests.cs
Update XML serializer tests to use target-typed newtest/RestSharp.Tests.Serializers.Xml/XmlSerializerTests.cs
(
new()instead ofnew DateTime(...))DateTime,Item,Person, andXElementtypes
RestRequestExtensions.Headers.cs
Refactor header extensions to C# 14 syntaxsrc/RestSharp/Request/RestRequestExtensions.Headers.cs
extension(RestRequest request)syntaxthisandstaticmodifiers from method signaturesrequestparameterreferences
NamespacedXmlTests.cs
Update namespaced XML tests to modern C# syntaxtest/RestSharp.Tests.Serializers.Xml/NamespacedXmlTests.cs
new DateTime(...)tonew(...)for cleaner syntaxnew Guid(...)andnew Uri(...)to use target-typed newRestRequestExtensions.File.cs
Refactor file extensions to C# 14 syntaxsrc/RestSharp/Request/RestRequestExtensions.File.cs
extension(RestRequest request)syntaxthisandstatickeywords from method declarationsrequestparameterentries
RestRequestExtensions.Object.cs
Refactor object extensions to C# 14 syntaxsrc/RestSharp/Request/RestRequestExtensions.Object.cs
extension(RestRequest request)syntaxthisandstaticmodifiers from all methodsrequestparameterreferences
BuildUriExtensions.cs
Refactor URI building extensions to C# 14src/RestSharp/BuildUriExtensions.cs
extension(IRestClient client)syntaxthisandstatickeywords from method signaturesclientparameter entriesRestResponseExtensions.cs
Refactor response extensions to C# 14 syntaxsrc/RestSharp/Response/RestResponseExtensions.cs
extension(RestResponse response)syntaxthisandstaticmodifiers from method declarationsresponseparameterreferences
RestRequestExtensions.Url.cs
Refactor URL segment extensions to C# 14src/RestSharp/Request/RestRequestExtensions.Url.cs
extension(RestRequestrequest)syntaxthisandstatickeywords from method signaturesrequestparameterentries
CsvHelperTests.cs
Update CSV serializer tests to modern C# syntaxtest/RestSharp.Tests.Serializers.Csv/CsvHelperTests.cs
using CsvHelper.Configurationimportnew RestRequest()tonew()andnew CsvConfiguration(...)tonew(...)RestClient.Async.cs
Update async client to use target-typed newsrc/RestSharp/RestClient.Async.cs
new CookieContainer()tonew()andnew HttpResponse(...)tonew(...)new HttpMethod(...)calls with target-typed new syntaxUriExtensions.cs
Update URI extensions to use target-typed newsrc/RestSharp/Request/UriExtensions.cs
new Uri(...)tonew(...)for cleaner syntaxRestRequestExtensions.Query.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Request/RestRequestExtensions.Query.cs
extensionkeywordextension(RestRequest request)blockthisparameter from method signaturesrequestparameterdocumentation
SerializerConfig.cs
Refactor to C# 14 extension syntax and target-typed newsrc/RestSharp/Serializers/SerializerConfig.cs
extensionsyntaxUseJson(),UseXml(), andUseOnlySerializer()methods insideextension(SerializerConfig config)blockthisparameter and updated method signaturesconfigparameter referencesSerializerRecordconstructor call to use target-typednew()syntax
XmlDeserializer.cs
Simplify initialization and use target-typed newsrc/RestSharp.Serializers.Xml/XmlDeserializer.cs
CulturepropertyXAttributeandGuidconstructor calls to use target-typednew()syntaxExtensions.cs
Refactor to C# 14 extension method syntaxgen/SourceGenerator/Extensions.cs
extensionsyntaxFindClasses()andFindAnnotatedClasses()methods insideextension(Compilation compilation)blockthisparameter from method signaturesTwitterClient.cs
Refactor to C# 14 primary constructor syntaxtest/RestSharp.InteractiveTests/TwitterClient.cs
TwitterAuthenticatorclass to use C# 14 primary constructorsyntax
directly
RestClientandAddSearchRulesRequestconstructor calls to usetarget-typed
new()syntaxObjectParser.cs
Use target-typed new and collection expressionssrc/RestSharp/Parameters/ObjectParser.cs
ParsedParameterconstructor calls to use target-typednew()syntax
new ParsedParameter[]to collectionexpression
[...]syntaxRequestArrayQueryType.CommaSeparatedcase to use target-typednew()with collection expressionIntegratedSimpleTests.cs
Use target-typed new constructor syntaxtest/RestSharp.Tests.Serializers.Json/NewtonsoftJson/IntegratedSimpleTests.cs
RestClientconstructor calls to use target-typednew()syntaxRestResponseconstructor calls to use target-typednew()syntax
RestRequestconstructor calls to use target-typednew()syntaxRange.cs
Use string interpolation and target-typed newsrc/RestSharp/Polyfills/Range.cs
ToString()method to use string interpolation instead ofconcatenation
StartAt(),EndAt(), andAllproperty to use target-typednew()syntax
XmlRestSerializer.cs
Add backing fields for primary constructor parameterssrc/RestSharp/Serializers/Xml/XmlRestSerializer.cs
_serializerand_deserializerfor primaryconstructor parameters
direct parameter access
consistently
SerializeAsAttribute.cs
Remove constructor and use property initializerssrc/RestSharp.Serializers.Xml/SerializeAsAttribute.cs
with default values
Culture,NameStyle, andIndexproperties with directinitialization
SystemTextJsonTests.cs
Use target-typed new constructor syntaxtest/RestSharp.Tests.Serializers.Json/SystemTextJson/SystemTextJsonTests.cs
RestClientconstructor calls to use target-typednew()syntaxRestResponseconstructor calls to use target-typednew()syntax
RestRequestconstructor calls to use target-typednew()syntaxParametersCollectionExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Parameters/ParametersCollectionExtensions.cs
extensionsyntaxGetQueryParameters()andGetContentParameters()methods insideextension(ParametersCollection parameters)blockthisparameter from method signaturesRestRequest.cs
Use C# 13 field keyword for propertiessrc/RestSharp/Request/RestRequest.cs
_advancedResponseHandlerand_responseWriterfield management
fieldcontextual keywordIndex.cs
Simplify methods with expression-bodied syntaxsrc/RestSharp/Polyfills/Index.cs
FromStart()andFromEnd()methods to use expression-bodiedsyntax with ternary operators
RestClientExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Serializers/Json/RestClientExtensions.cs
extensionsyntaxUseSystemTextJson()overloads insideextension(SerializerConfigserializerConfig)blockthisparameter from method signaturesserializerConfigparameterreferences
StringExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs
extensionsyntaxextension(string left)blockthisparameter and renamed first parameter toleftRestClientExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp.Serializers.NewtonsoftJson/RestClientExtensions.cs
extensionsyntaxUseNewtonsoftJson()overloads insideextension(SerializerConfigconfig)blockthisparameter from method signaturesconfigparameter referencesRequestContent.cs
Use target-typed new constructor syntaxsrc/RestSharp/Request/RequestContent.cs
ContentDispositionHeaderValueconstructor call to usetarget-typed
new()syntaxNameValueHeaderValueconstructor call to use target-typednew()syntaxResponseThrowExtension.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Response/ResponseThrowExtension.cs
extensionsyntaxThrowIfError()methods inside separateextensionblocks for eachtype
expressions
thisparameter from method signaturesFileParameter.cs
Use target-typed new constructor syntaxsrc/RestSharp/Parameters/FileParameter.cs
FileParameterconstructor calls to use target-typednew()syntax in
Create()andFromFile()methodsAuthenticationTests.cs
Use target-typed new and string interpolationtest/RestSharp.InteractiveTests/AuthenticationTests.cs
RestRequestconstructor calls to use target-typednew()syntaxarguments
DotNetXmlSerializer.cs
Refactor to C# 14 primary constructor syntaxsrc/RestSharp/Serializers/Xml/DotNetXmlSerializer.cs
EncodingStringWriterclass to use C# 14 primary constructorsyntax
Encodingproperty to use inline initialization with primaryconstructor parameter
XmlSerializerconstructor call to use target-typednew()syntax
OAuthTools.cs
Use target-typed new constructor syntaxsrc/RestSharp/Authenticators/OAuth/OAuthTools.cs
Randomconstructor call to use target-typednew()syntaxstringconstructor call to use target-typednew()syntaxCsvHelperSerializer.cs
Use target-typed new constructor syntaxsrc/RestSharp.Serializers.CsvHelper/CsvHelperSerializer.cs
CsvConfigurationconstructor call to use target-typednew()syntax
WebPairCollection.cs
Use target-typed new constructor syntaxsrc/RestSharp/Authenticators/OAuth/WebPairCollection.cs
WebPairconstructor calls to use target-typednew()syntax inAdd()andAddNotEmpty()methodsAddObjectToRequestParametersBenchmarks.cs
Use target-typed new constructor syntaxbenchmarks/RestSharp.Benchmarks/Requests/AddObjectToRequestParametersBenchmarks.cs
Dataconstructor call to use target-typednew()syntaxBodyExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp/Request/BodyExtensions.cs
extensionsyntaxTryGetBodyParameter()andHasFiles()methods insideextension(RestRequest request)blockthisparameter from method signaturesSimpleServer.cs
Use target-typed new constructor syntaxtest/RestSharp.Tests.Shared/Fixtures/SimpleServer.cs
WebServerconstructor call to use target-typednew()syntaxSimpleServerconstructor call to use target-typednew()syntaxPropertyCache.Populator.cs
Use target-typed new constructor syntaxsrc/RestSharp/Request/PropertyCache.Populator.cs
Populatorconstructor call to use target-typednew()syntaxContentType.cs
Use target-typed new constructor syntaxsrc/RestSharp/ContentType.cs
ContentTypeconstructor call to use target-typednew()syntaxin implicit operator
JsonNetSerializer.cs
Use target-typed new constructor syntaxsrc/RestSharp.Serializers.NewtonsoftJson/JsonNetSerializer.cs
WriterBufferconstructor call to use target-typednew()syntaxRestClientExtensions.cs
Refactor to C# 14 extension method syntaxsrc/RestSharp.Serializers.CsvHelper/RestClientExtensions.cs
extensionsyntaxUseCsvHelper()overloads insideextension(SerializerConfigconfig)blockthisparameter from method signaturesSystemTextJsonSerializer.cs
Use target-typed new constructor syntaxsrc/RestSharp/Serializers/Json/SystemTextJsonSerializer.cs
JsonSerializerOptionsconstructor call to use target-typednew()syntaxPropertyCache.Populator.RequestProperty.cs
Use target-typed new constructor syntaxsrc/RestSharp/Request/PropertyCache.Populator.RequestProperty.cs
RequestPropertyconstructor call to use target-typednew()syntax
RequestBodyCapturer.cs
Use target-typed new constructor syntaxtest/RestSharp.Tests.Shared/Fixtures/RequestBodyCapturer.cs
Uriconstructor call to use target-typednew()syntax1 files
RestRequestTests.cs
Enhance query parameter parsing test coveragetest/RestSharp.Tests/RestRequestTests.cs
1 files
Handlers.cs
Add null-safety check for URL propertytest/RestSharp.Tests.Shared/Fixtures/Handlers.cs
ctx.Request.Urlaccess for nullsafety
1 files
pull-request.yml
Add .NET 10 RC 2 support to CI/CD pipeline.github/workflows/pull-request.yml
upload-artifact,checkout, andsetup-dotnet2 files