Skip to content

Conversation

@alexeyzimarev
Copy link
Member

@alexeyzimarev alexeyzimarev commented Nov 12, 2025

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 extension syntax with extension blocks

  • Updated object instantiation throughout to use target-typed new() expressions for cleaner code

  • Refactored classes to use C# 14 primary constructor syntax where applicable

  • Applied C# 13 field keyword for automatic backing field management in properties

  • Modernized 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

flowchart LR
  A["Legacy C# Code<br/>Static Extensions<br/>Verbose Constructors"] -->|"C# 14 Refactoring"| B["Modern C# Code<br/>Extension Blocks<br/>Target-typed new"]
  B -->|"Primary Constructors"| C["Simplified Classes<br/>Reduced Boilerplate"]
  B -->|"Field Keyword"| D["Auto Backing Fields<br/>Cleaner Properties"]
  E["CI/CD Pipeline"] -->|"Add .NET 10 RC 2"| F[".NET 10 Testing<br/>GitHub Actions v5"]
Loading

File Walkthrough

Relevant files
Enhancement
62 files
XmlDeserializerTests.cs
C# 14 modernization with target-typed new expressions       

test/RestSharp.Tests.Serializers.Xml/XmlDeserializerTests.cs

  • Replaced verbose new RestResponse { Content = ... } with target-typed
    new() { Content = ... } syntax (C# 9 feature)
  • Changed new DateTime(...) and new TimeSpan(...) to target-typed
    new(...) syntax
  • Changed new Guid(...) and new Uri(...) to target-typed new(...) syntax
  • Replaced Assert.False(x == 0) with Assert.NotEqual(0, x) for clearer
    test assertions
  • Reformatted multi-line lambda expressions to single-line format
+57/-70 
RestClient.Extensions.Get.cs
Refactored to C# 11 extension method syntax                           

src/RestSharp/RestClient.Extensions.Get.cs

  • Converted extension methods from static methods to instance methods
    using C# 11 extension syntax
  • Wrapped all methods inside extension(IRestClient client) block
  • Removed this keyword and IRestClient client parameter from method
    signatures
  • Updated XML documentation to remove client parameter references
  • Changed new RestRequest(resource) to target-typed new(resource) syntax
+185/-202
RestClient.Extensions.Delete.cs
Refactored to C# 11 extension method syntax                           

src/RestSharp/RestClient.Extensions.Delete.cs

  • Converted extension methods from static methods to instance methods
    using C# 11 extension syntax
  • Wrapped all methods inside extension(IRestClient client) block
  • Removed this keyword and IRestClient client parameter from method
    signatures
  • Updated XML documentation to remove client parameter references
+158/-173
RestClient.Extensions.Put.cs
Refactored to C# 11 extension method syntax                           

src/RestSharp/RestClient.Extensions.Put.cs

  • Converted extension methods from static methods to instance methods
    using C# 11 extension syntax
  • Wrapped all methods inside extension(IRestClient client) block
  • Removed this keyword and IRestClient client parameter from method
    signatures
  • Updated XML documentation to remove client parameter references
+129/-143
RestClient.Extensions.Post.cs
Refactored to C# 11 extension method syntax                           

src/RestSharp/RestClient.Extensions.Post.cs

  • Converted extension methods from static methods to instance methods
    using C# 11 extension syntax
  • Wrapped all methods inside extension(IRestClient client) block
  • Removed this keyword and IRestClient client parameter from method
    signatures
  • Updated XML documentation to remove client parameter references
+129/-143
XmlAttributeDeserializerTests.cs
C# 14 modernization with target-typed new expressions       

test/RestSharp.Tests.Serializers.Xml/XmlAttributeDeserializerTests.cs

  • Replaced verbose new RestResponse { Content = ... } with target-typed
    new() { Content = ... } syntax
  • Changed new DateTime(...), new TimeSpan(...), new Guid(...), and new
    Uri(...) to target-typed new(...) syntax
  • Replaced Assert.False(x == 0) with Assert.NotEqual(0, x) for clearer
    test assertions
+47/-49 
RestClient.Extensions.cs
Refactored to C# 11 extension method syntax                           

src/RestSharp/RestClient.Extensions.cs

  • Converted extension methods from static methods to instance methods
    using C# 11 extension syntax
  • Wrapped all methods inside extension(IRestClient client) block
  • Removed this keyword and IRestClient client parameter from method
    signatures
  • Updated XML documentation to remove client parameter references
  • Improved code indentation and formatting consistency
+143/-156
OAuthWorkflow.cs
C# 14 modernization with target-typed new expressions       

src/RestSharp/Authenticators/OAuth/OAuthWorkflow.cs

  • Changed new OAuthParameters { ... } to target-typed new() { ... }
    syntax
  • Changed new WebPair(...) to target-typed new(...) syntax in collection
    initializer
  • Improved variable alignment formatting for uri variable declaration
+13/-13 
WriterBuffer.cs
C# 14 modernization and cleanup                                                   

src/RestSharp.Serializers.NewtonsoftJson/WriterBuffer.cs

  • Removed unused using System.Text; directive
  • Changed new StringWriter(new StringBuilder(256), ...) to target-typed
    new(new(256), ...) syntax
  • Changed new JsonTextWriter(_stringWriter) to target-typed
    new(_stringWriter) syntax
+2/-3     
RestRequestExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Request/RestRequestExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax with
    extension(RestRequest request) blocks
  • Removed this keyword and static modifiers from methods within
    extension blocks
  • Updated XML documentation to remove redundant request parameter
    references
  • Changed new CookieContainer() to new() using target-typed new
    expressions
+108/-114
StringExtensions.cs
Refactor string extensions to C# 14 syntax                             

src/RestSharp/Extensions/StringExtensions.cs

  • Refactored string extension methods to use C# 14 extension(string
    input) syntax
  • Removed this keyword and static modifiers from methods within
    extension blocks
  • Updated XML documentation to remove redundant parameter references
  • Reorganized methods into logical extension blocks for better code
    organization
+109/-104
RestRequestExtensions.Body.cs
Convert body extensions to C# 14 syntax                                   

src/RestSharp/Request/RestRequestExtensions.Body.cs

  • Converted body-related extension methods to C# 14
    extension(RestRequest request) syntax
  • Removed this and static keywords from method signatures
  • Updated XML documentation to remove redundant request parameter
    entries
  • Simplified method structure within extension blocks
+88/-90 
RestClient.Extensions.Patch.cs
Refactor PATCH client extensions to C# 14                               

src/RestSharp/RestClient.Extensions.Patch.cs

  • Refactored PATCH HTTP method extensions to use C# 14
    extension(IRestClient client) syntax
  • Removed this and static modifiers from all extension methods
  • Updated XML documentation to remove redundant client parameter
    references
  • Maintained all method functionality and signatures
+74/-82 
RestClient.Extensions.Head.cs
Refactor HEAD client extensions to C# 14                                 

src/RestSharp/RestClient.Extensions.Head.cs

  • Converted HEAD HTTP method extensions to C# 14 extension(IRestClient
    client) syntax
  • Removed this and static keywords from method declarations
  • Updated XML documentation to remove redundant parameter references
  • Preserved all method implementations and behavior
+73/-79 
RestClient.Extensions.Options.cs
Refactor OPTIONS client extensions to C# 14                           

src/RestSharp/RestClient.Extensions.Options.cs

  • Refactored OPTIONS HTTP method extensions to use C# 14
    extension(IRestClient client) syntax
  • Removed this and static modifiers from extension methods
  • Updated XML documentation to remove redundant client parameter entries
  • Maintained all method signatures and implementations
+73/-79 
RestClient.Extensions.Params.cs
Refactor parameter client extensions to C# 14                       

src/RestSharp/RestClient.Extensions.Params.cs

  • Converted parameter-related client extensions to C# 14
    extension(IRestClient client) syntax
  • Removed this and static keywords from all methods
  • Updated XML documentation to remove redundant client parameter
    references
  • Simplified method organization within extension blocks
+67/-71 
XmlSerializerTests.cs
Update XML serializer tests to use target-typed new           

test/RestSharp.Tests.Serializers.Xml/XmlSerializerTests.cs

  • Updated object instantiation to use target-typed new expressions
    (new() instead of new DateTime(...))
  • Simplified constructor calls for DateTime, Item, Person, and XElement
    types
  • Improved code readability with modern C# syntax
+33/-33 
RestRequestExtensions.Headers.cs
Refactor header extensions to C# 14 syntax                             

src/RestSharp/Request/RestRequestExtensions.Headers.cs

  • Refactored header-related extension methods to use C# 14
    extension(RestRequest request) syntax
  • Removed this and static modifiers from method signatures
  • Updated XML documentation to remove redundant request parameter
    references
  • Organized methods within extension blocks
+69/-73 
NamespacedXmlTests.cs
Update namespaced XML tests to modern C# syntax                   

test/RestSharp.Tests.Serializers.Xml/NamespacedXmlTests.cs

  • Updated object instantiation to use target-typed new expressions
  • Changed new DateTime(...) to new(...) for cleaner syntax
  • Updated new Guid(...) and new Uri(...) to use target-typed new
  • Fixed formatting and alignment in XML element creation
+28/-28 
RestRequestExtensions.File.cs
Refactor file extensions to C# 14 syntax                                 

src/RestSharp/Request/RestRequestExtensions.File.cs

  • Converted file-related extension methods to C# 14
    extension(RestRequest request) syntax
  • Removed this and static keywords from method declarations
  • Updated XML documentation to remove redundant request parameter
    entries
  • Improved method organization within extension blocks
+61/-64 
RestRequestExtensions.Object.cs
Refactor object extensions to C# 14 syntax                             

src/RestSharp/Request/RestRequestExtensions.Object.cs

  • Refactored object-related extension methods to use C# 14
    extension(RestRequest request) syntax
  • Removed this and static modifiers from all methods
  • Updated XML documentation to remove redundant request parameter
    references
  • Maintained all method functionality and signatures
+42/-42 
BuildUriExtensions.cs
Refactor URI building extensions to C# 14                               

src/RestSharp/BuildUriExtensions.cs

  • Converted URI building extension methods to C# 14
    extension(IRestClient client) syntax
  • Removed this and static keywords from method signatures
  • Updated XML documentation to remove redundant client parameter entries
  • Organized methods within extension blocks
+56/-56 
RestResponseExtensions.cs
Refactor response extensions to C# 14 syntax                         

src/RestSharp/Response/RestResponseExtensions.cs

  • Refactored response extension methods to use C# 14
    extension(RestResponse response) syntax
  • Removed this and static modifiers from method declarations
  • Updated XML documentation to remove redundant response parameter
    references
  • Simplified method organization within extension blocks
+38/-39 
RestRequestExtensions.Url.cs
Refactor URL segment extensions to C# 14                                 

src/RestSharp/Request/RestRequestExtensions.Url.cs

  • Converted URL segment extension methods to C# 14 extension(RestRequest
    request) syntax
  • Removed this and static keywords from method signatures
  • Updated XML documentation to remove redundant request parameter
    entries
  • Maintained all method implementations
+22/-21 
CsvHelperTests.cs
Update CSV serializer tests to modern C# syntax                   

test/RestSharp.Tests.Serializers.Csv/CsvHelperTests.cs

  • Removed unused using CsvHelper.Configuration import
  • Updated object instantiation to use target-typed new expressions
  • Changed new RestRequest() to new() and new CsvConfiguration(...) to
    new(...)
  • Simplified DateTime constructor calls with target-typed new syntax
+15/-25 
RestClient.Async.cs
Update async client to use target-typed new                           

src/RestSharp/RestClient.Async.cs

  • Updated object instantiation to use target-typed new expressions
  • Changed new CookieContainer() to new() and new HttpResponse(...) to
    new(...)
  • Simplified new HttpMethod(...) calls with target-typed new syntax
  • Improved code readability with modern C# 14 features
+7/-7     
UriExtensions.cs
Update URI extensions to use target-typed new                       

src/RestSharp/Request/UriExtensions.cs

  • Updated URI instantiation to use target-typed new expressions
  • Changed new Uri(...) to new(...) for cleaner syntax
  • Improved code readability with modern C# features
+2/-2     
RestRequestExtensions.Query.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Request/RestRequestExtensions.Query.cs

  • Refactored extension methods to use C# 14 extension syntax with
    extension keyword
  • Moved methods inside extension(RestRequest request) block
  • Removed this parameter from method signatures
  • Updated XML documentation to remove redundant request parameter
    documentation
+22/-21 
SerializerConfig.cs
Refactor to C# 14 extension syntax and target-typed new   

src/RestSharp/Serializers/SerializerConfig.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved UseJson(), UseXml(), and UseOnlySerializer() methods inside
    extension(SerializerConfig config) block
  • Removed this parameter and updated method signatures
  • Updated XML documentation to remove config parameter references
  • Changed SerializerRecord constructor call to use target-typed new()
    syntax
+28/-28 
XmlDeserializer.cs
Simplify initialization and use target-typed new                 

src/RestSharp.Serializers.Xml/XmlDeserializer.cs

  • Converted constructor initialization to property initializer for
    Culture property
  • Removed explicit constructor body in favor of inline initialization
  • Updated XAttribute and Guid constructor calls to use target-typed
    new() syntax
+3/-5     
Extensions.cs
Refactor to C# 14 extension method syntax                               

gen/SourceGenerator/Extensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved FindClasses() and FindAnnotatedClasses() methods inside
    extension(Compilation compilation) block
  • Removed this parameter from method signatures
  • Improved code organization with nested local function
+14/-12 
TwitterClient.cs
Refactor to C# 14 primary constructor syntax                         

test/RestSharp.InteractiveTests/TwitterClient.cs

  • Converted TwitterAuthenticator class to use C# 14 primary constructor
    syntax
  • Removed explicit field declarations and constructor body
  • Updated field references to use primary constructor parameters
    directly
  • Changed RestClient and AddSearchRulesRequest constructor calls to use
    target-typed new() syntax
+5/-15   
ObjectParser.cs
Use target-typed new and collection expressions                   

src/RestSharp/Parameters/ObjectParser.cs

  • Updated ParsedParameter constructor calls to use target-typed new()
    syntax
  • Changed array initialization from new ParsedParameter[] to collection
    expression [...] syntax
  • Updated RequestArrayQueryType.CommaSeparated case to use target-typed
    new() with collection expression
+3/-3     
IntegratedSimpleTests.cs
Use target-typed new constructor syntax                                   

test/RestSharp.Tests.Serializers.Json/NewtonsoftJson/IntegratedSimpleTests.cs

  • Updated RestClient constructor calls to use target-typed new() syntax
  • Changed RestResponse constructor calls to use target-typed new()
    syntax
  • Updated RestRequest constructor calls to use target-typed new() syntax
+4/-4     
Range.cs
Use string interpolation and target-typed new                       

src/RestSharp/Polyfills/Range.cs

  • Converted ToString() method to use string interpolation instead of
    concatenation
  • Updated StartAt(), EndAt(), and All property to use target-typed new()
    syntax
+4/-4     
XmlRestSerializer.cs
Add backing fields for primary constructor parameters       

src/RestSharp/Serializers/Xml/XmlRestSerializer.cs

  • Added private backing fields _serializer and _deserializer for primary
    constructor parameters
  • Updated property implementations to use backing fields instead of
    direct parameter access
  • Updated method implementations to reference backing fields
    consistently
+11/-8   
SerializeAsAttribute.cs
Remove constructor and use property initializers                 

src/RestSharp.Serializers.Xml/SerializeAsAttribute.cs

  • Removed explicit parameterless constructor
  • Converted property initializations to inline property initializers
    with default values
  • Updated Culture, NameStyle, and Index properties with direct
    initialization
+3/-9     
SystemTextJsonTests.cs
Use target-typed new constructor syntax                                   

test/RestSharp.Tests.Serializers.Json/SystemTextJson/SystemTextJsonTests.cs

  • Updated RestClient constructor calls to use target-typed new() syntax
  • Changed RestResponse constructor calls to use target-typed new()
    syntax
  • Updated RestRequest constructor calls to use target-typed new() syntax
+4/-4     
ParametersCollectionExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Parameters/ParametersCollectionExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved GetQueryParameters() and GetContentParameters() methods inside
    extension(ParametersCollection parameters) block
  • Removed this parameter from method signatures
  • Updated collection expression syntax for empty array
+11/-9   
RestRequest.cs
Use C# 13 field keyword for properties                                     

src/RestSharp/Request/RestRequest.cs

  • Removed explicit backing fields _advancedResponseHandler and
    _responseWriter
  • Converted properties to use C# 13 field keyword for automatic backing
    field management
  • Simplified property declarations with field contextual keyword
+4/-7     
Index.cs
Simplify methods with expression-bodied syntax                     

src/RestSharp/Polyfills/Index.cs

  • Refactored FromStart() and FromEnd() methods to use expression-bodied
    syntax with ternary operators
  • Simplified validation logic using throw expressions
  • Reduced method body verbosity
+2/-14   
RestClientExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Serializers/Json/RestClientExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved UseSystemTextJson() overloads inside extension(SerializerConfig
    serializerConfig) block
  • Removed this parameter from method signatures
  • Updated XML documentation to remove serializerConfig parameter
    references
+15/-14 
StringExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Authenticators/OAuth/Extensions/StringExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved all string extension methods inside extension(string left) block
  • Removed this parameter and renamed first parameter to left
  • Updated method bodies to reference parameter directly
+7/-5     
RestClientExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp.Serializers.NewtonsoftJson/RestClientExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved UseNewtonsoftJson() overloads inside extension(SerializerConfig
    config) block
  • Removed this parameter from method signatures
  • Updated XML documentation to remove config parameter references
+14/-13 
RequestContent.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Request/RequestContent.cs

  • Updated ContentDispositionHeaderValue constructor call to use
    target-typed new() syntax
  • Changed NameValueHeaderValue constructor call to use target-typed
    new() syntax
+2/-2     
ResponseThrowExtension.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Response/ResponseThrowExtension.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved ThrowIfError() methods inside separate extension blocks for each
    type
  • Simplified method bodies using ternary operators with throw
    expressions
  • Removed this parameter from method signatures
+10/-10 
FileParameter.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Parameters/FileParameter.cs

  • Updated FileParameter constructor calls to use target-typed new()
    syntax in Create() and FromFile() methods
+2/-2     
AuthenticationTests.cs
Use target-typed new and string interpolation                       

test/RestSharp.InteractiveTests/AuthenticationTests.cs

  • Updated RestRequest constructor calls to use target-typed new() syntax
  • Changed string concatenation to string interpolation in constructor
    arguments
+3/-3     
DotNetXmlSerializer.cs
Refactor to C# 14 primary constructor syntax                         

src/RestSharp/Serializers/Xml/DotNetXmlSerializer.cs

  • Converted EncodingStringWriter class to use C# 14 primary constructor
    syntax
  • Removed explicit constructor body
  • Updated Encoding property to use inline initialization with primary
    constructor parameter
  • Updated XmlSerializer constructor call to use target-typed new()
    syntax
+4/-5     
OAuthTools.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Authenticators/OAuth/OAuthTools.cs

  • Updated Random constructor call to use target-typed new() syntax
  • Changed string constructor call to use target-typed new() syntax
+2/-2     
CsvHelperSerializer.cs
Use target-typed new constructor syntax                                   

src/RestSharp.Serializers.CsvHelper/CsvHelperSerializer.cs

  • Updated CsvConfiguration constructor call to use target-typed new()
    syntax
+1/-1     
WebPairCollection.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Authenticators/OAuth/WebPairCollection.cs

  • Updated WebPair constructor calls to use target-typed new() syntax in
    Add() and AddNotEmpty() methods
+2/-2     
AddObjectToRequestParametersBenchmarks.cs
Use target-typed new constructor syntax                                   

benchmarks/RestSharp.Benchmarks/Requests/AddObjectToRequestParametersBenchmarks.cs

  • Updated Data constructor call to use target-typed new() syntax
+1/-1     
BodyExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp/Request/BodyExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved TryGetBodyParameter() and HasFiles() methods inside
    extension(RestRequest request) block
  • Removed this parameter from method signatures
+7/-5     
SimpleServer.cs
Use target-typed new constructor syntax                                   

test/RestSharp.Tests.Shared/Fixtures/SimpleServer.cs

  • Updated WebServer constructor call to use target-typed new() syntax
  • Updated SimpleServer constructor call to use target-typed new() syntax
+2/-2     
PropertyCache.Populator.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Request/PropertyCache.Populator.cs

  • Updated Populator constructor call to use target-typed new() syntax
+1/-1     
ContentType.cs
Use target-typed new constructor syntax                                   

src/RestSharp/ContentType.cs

  • Updated ContentType constructor call to use target-typed new() syntax
    in implicit operator
+1/-1     
JsonNetSerializer.cs
Use target-typed new constructor syntax                                   

src/RestSharp.Serializers.NewtonsoftJson/JsonNetSerializer.cs

  • Updated WriterBuffer constructor call to use target-typed new() syntax
+1/-1     
RestClientExtensions.cs
Refactor to C# 14 extension method syntax                               

src/RestSharp.Serializers.CsvHelper/RestClientExtensions.cs

  • Refactored extension methods to use C# 14 extension syntax
  • Moved UseCsvHelper() overloads inside extension(SerializerConfig
    config) block
  • Removed this parameter from method signatures
+5/-3     
SystemTextJsonSerializer.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Serializers/Json/SystemTextJsonSerializer.cs

  • Updated JsonSerializerOptions constructor call to use target-typed
    new() syntax
+1/-1     
PropertyCache.Populator.RequestProperty.cs
Use target-typed new constructor syntax                                   

src/RestSharp/Request/PropertyCache.Populator.RequestProperty.cs

  • Updated RequestProperty constructor call to use target-typed new()
    syntax
+1/-1     
RequestBodyCapturer.cs
Use target-typed new constructor syntax                                   

test/RestSharp.Tests.Shared/Fixtures/RequestBodyCapturer.cs

  • Updated Uri constructor call to use target-typed new() syntax
+1/-1     
Tests
1 files
RestRequestTests.cs
Enhance query parameter parsing test coverage                       

test/RestSharp.Tests/RestRequestTests.cs

  • Added test constants for resource and base URL
  • Updated test to verify three query parameters instead of two
  • Added assertion for empty value parameter
  • Added integration test for URI building with base URL
+11/-3   
Bug fix
1 files
Handlers.cs
Add null-safety check for URL property                                     

test/RestSharp.Tests.Shared/Fixtures/Handlers.cs

  • Added null-coalescing operator to ctx.Request.Url access for null
    safety
+1/-1     
Configuration changes
1 files
pull-request.yml
Add .NET 10 RC 2 support to CI/CD pipeline                             

.github/workflows/pull-request.yml

  • Updated GitHub Actions versions from v4 to v5 for upload-artifact,
    checkout, and setup-dotnet
  • Added .NET 10 RC 2 setup step with preview quality specification
  • Added .NET 10 to test matrix for both Windows and Ubuntu runners
+21/-7   
Additional files
2 files
Directory.Build.props +1/-1     
RestSharp.csproj +6/-0     

@qodo-merge-for-open-source
Copy link

qodo-merge-for-open-source bot commented Nov 12, 2025

PR Compliance Guide 🔍

(Compliance updated until commit 109ab58)

Below is a summary of compliance checks for this PR:

Security Compliance
Incomplete response initialization

Description: Using target-typed new() without specifying the type creates an anonymous RestResponse
object that may not properly initialize security-critical properties like headers,
cookies, or response validation flags, potentially bypassing security checks in the
deserialization pipeline.
XmlDeserializerTests.cs [360-360]

Referred Code
var output      = xml.Deserialize<Header>(new() { Content = doc.ToString() })!;
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Previous compliance checks

Compliance check up to commit 109ab58
Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

@qodo-merge-for-open-source
Copy link

qodo-merge-for-open-source bot commented Nov 12, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Refactor to use an experimental feature

The suggestion advises against refactoring the codebase to use the experimental
C# extension feature due to the high risk of breaking changes. It recommends
waiting for the feature's official stable release.

Examples:

src/RestSharp/RestClient.Extensions.Get.cs [20-209]
    extension(IRestClient client) {
        /// <summary>
        /// Executes a GET-style asynchronously, authenticating if needed.
        /// </summary>
        /// <param name="request">Request to be executed</param>
        /// <param name="cancellationToken">Cancellation token</param>
        public Task<RestResponse> ExecuteGetAsync(RestRequest request, CancellationToken cancellationToken = default)
            => client.ExecuteAsync(request, Method.Get, cancellationToken);

        /// <summary>

 ... (clipped 180 lines)
src/RestSharp/Request/RestRequestExtensions.cs [20-140]
    extension(RestRequest request) {
        /// <summary>
        /// Adds a HTTP parameter to the request (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
        /// </summary>
        /// <param name="name">Name of the parameter</param>
        /// <param name="value">Value of the parameter</param>
        /// <param name="encode">Encode the value or not, default true</param>
        /// <returns>This request</returns>
        public RestRequest AddParameter(string name, string? value, bool encode = true)
            => request.AddParameter(new GetOrPostParameter(name, value, encode));

 ... (clipped 111 lines)

Solution Walkthrough:

Before:

// In files like 'src/RestSharp/RestClient.Extensions.Get.cs'
public static partial class RestClientExtensions {
    /// <summary>
    /// Executes a GET-style asynchronously, authenticating if needed.
    /// </summary>
    public static Task<RestResponse> ExecuteGetAsync(this IRestClient client, RestRequest request, CancellationToken cancellationToken = default)
        => client.ExecuteAsync(request, Method.Get, cancellationToken);

    /// <summary>
    /// Executes a GET-style request asynchronously, authenticating if needed.
    /// The response content then gets deserialized to T.
    /// </summary>
    public static Task<RestResponse<T>> ExecuteGetAsync<T>(
        this IRestClient  client,
        RestRequest       request,
        CancellationToken cancellationToken = default
    ) => client.ExecuteAsync<T>(request, Method.Get, cancellationToken);
    // ... and so on for all extension methods
}

After:

// In files like 'src/RestSharp/RestClient.Extensions.Get.cs'
public static partial class RestClientExtensions {
    /// <param name="client"></param>
    extension(IRestClient client) {
        /// <summary>
        /// Executes a GET-style asynchronously, authenticating if needed.
        /// </summary>
        public Task<RestResponse> ExecuteGetAsync(RestRequest request, CancellationToken cancellationToken = default)
            => client.ExecuteAsync(request, Method.Get, cancellationToken);

        /// <summary>
        /// Executes a GET-style request asynchronously, authenticating if needed.
        /// The response content then gets deserialized to T.
        /// </summary>
        public Task<RestResponse<T>> ExecuteGetAsync<T>(
            RestRequest       request,
            CancellationToken cancellationToken = default
        ) => client.ExecuteAsync<T>(request, Method.Get, cancellationToken);
        // ... and so on for all methods inside the extension block
    }
}
Suggestion importance[1-10]: 10

__

Why: This is a critical, high-impact suggestion addressing a major architectural decision to adopt an experimental language feature across the entire library, which introduces significant risk.

High
Possible issue
Fix infinite recursion in method

Fix an infinite recursion in GetJsonAsync by casting client to IRestClient to
ensure the call is dispatched to the correct GetAsync implementation.

src/RestSharp/RestClient.Extensions.Get.cs [188-194]

 [Obsolete("Use GetAsync instead")]
 public Task<TResponse?> GetJsonAsync<TResponse>(
     string            resource,
     object            parameters,
     CancellationToken cancellationToken = default
 )
-    => client.GetAsync<TResponse>(resource, parameters, cancellationToken);
+    => ((IRestClient)client).GetAsync<TResponse>(resource, parameters, cancellationToken);
  • Apply / Chat
Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies a critical bug where an obsolete method forwarding call creates an infinite recursion, which would cause a StackOverflowException at runtime.

High
Fix illegal assignment to extension parameter

The input parameter of an extension type is immutable. Replace the reassignment
input = input.Replace('_', ' '); with a new local variable to store the result
and avoid a compilation error.

src/RestSharp/Extensions/StringExtensions.cs [83-94]

     internal string ToPascalCase(bool removeUnderscores, CultureInfo culture) {
         if (string.IsNullOrEmpty(input)) return input;
 
-        input = input.Replace('_', ' ');
+        var text = input.Replace('_', ' ');
 
         var joinString = removeUnderscores ? string.Empty : "_";
-        var words      = input.Split(' ');
+        var words      = text.Split(' ');
 
         return words
             .Where(x => x.Length > 0)
             .Select(CaseWord)
             .JoinToString(joinString);
 ...

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies a compilation error caused by reassigning the input parameter of an extension type, which is immutable, and provides the correct fix.

High
Fix incorrect extension method call

Fix an incorrect method call inside an extension block. The call to
AddHeader(request, name, value) should be changed to request.AddHeader(name,
value) to match the new instance-like method syntax and avoid a compilation
error.

src/RestSharp/Request/RestRequestExtensions.Headers.cs [26-32]

     public RestRequest AddHeader(string name, string[] values) {
         foreach (var value in values) {
-            AddHeader(request, name, value);
+            request.AddHeader(name, value);
         }
 
         return request;
     }
  • Apply / Chat
Suggestion importance[1-10]: 10

__

Why: The suggestion correctly identifies a compilation error where a method call AddHeader(request, name, value) uses an old static extension method syntax inside a new extension block, and provides the correct fix.

High
Prevent race conditions in properties

Add a lock to the setters of ResponseWriter and AdvancedResponseWriter to
prevent a race condition and ensure mutual exclusivity in a multi-threaded
environment.

src/RestSharp/Request/RestRequest.cs [211-234]

+private readonly object _writerLock = new();
 public Func<Stream, Stream?>? ResponseWriter {
     get;
     set {
-        if (AdvancedResponseWriter != null) {
-            throw new ArgumentException("AdvancedResponseWriter is not null. Only one response writer can be used.");
+        lock (_writerLock) {
+            if (AdvancedResponseWriter != null) {
+                throw new ArgumentException("AdvancedResponseWriter is not null. Only one response writer can be used.");
+            }
+    
+            field = value;
         }
-
-        field = value;
     }
 }
 
 /// <summary>
 /// Set this to handle the response stream yourself, based on the response details
 /// </summary>
 public Func<HttpResponseMessage, RestRequest, RestResponse>? AdvancedResponseWriter {
     get;
     set {
-        if (ResponseWriter != null) {
-            throw new ArgumentException("ResponseWriter is not null. Only one response writer can be used.");
+        lock (_writerLock) {
+            if (ResponseWriter != null) {
+                throw new ArgumentException("ResponseWriter is not null. Only one response writer can be used.");
+            }
+    
+            field = value;
         }
-
-        field = value;
     }
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential race condition between the ResponseWriter and AdvancedResponseWriter properties and proposes a valid fix using a lock to ensure thread safety.

Medium
General
Simplify code with primary constructors

Refactor XmlRestSerializer to use primary constructor parameters directly,
removing the redundant _serializer and _deserializer fields.

src/RestSharp/Serializers/Xml/XmlRestSerializer.cs [17-56]

 public class XmlRestSerializer(IXmlSerializer serializer, IXmlDeserializer deserializer) : IRestSerializer {
-    IXmlDeserializer _deserializer = deserializer;
-    IXmlSerializer   _serializer   = serializer;
-
     public XmlRestSerializer() : this(new DotNetXmlSerializer(), new DotNetXmlDeserializer()) { }
 
-    public ISerializer         Serializer           => _serializer;
-    public IDeserializer       Deserializer         => _deserializer;
+    public ISerializer         Serializer           => serializer;
+    public IDeserializer       Deserializer         => deserializer;
     public string[]            AcceptedContentTypes => ContentType.XmlAccept;
     public SupportsContentType SupportsContentType  => contentType => contentType.Value.EndsWith("xml", StringComparison.InvariantCultureIgnoreCase);
 
     public DataFormat DataFormat => DataFormat.Xml;
 
     public string? Serialize(Parameter parameter) {
         if (parameter is not XmlParameter xmlParameter)
             throw new ArgumentException("Parameter is not an XML parameter", nameof(parameter));
 
         if (parameter.Value == null)
             throw new ArgumentNullException(nameof(parameter), "Parameter value is null");
 
-        var savedNamespace = _serializer.Namespace;
-        _serializer.Namespace = xmlParameter.XmlNamespace ?? savedNamespace;
+        var savedNamespace = serializer.Namespace;
+        serializer.Namespace = xmlParameter.XmlNamespace ?? savedNamespace;
 
-        var result = _serializer.Serialize(parameter.Value);
+        var result = serializer.Serialize(parameter.Value);
 
-        _serializer.Namespace = savedNamespace;
+        serializer.Namespace = savedNamespace;
 
         return result;
     }
 
     public XmlRestSerializer WithXmlSerializer(IXmlSerializer xmlSerializer) {
-        _serializer = xmlSerializer;
+        serializer = xmlSerializer;
         return this;
     }
 
     public XmlRestSerializer WithXmlDeserializer(IXmlDeserializer xmlDeserializer) {
-        _deserializer = xmlDeserializer;
+        deserializer = xmlDeserializer;
         return this;
     }
 }

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that the explicit private fields _serializer and _deserializer are redundant, as primary constructor parameters can be used directly, simplifying the code.

Low
Improve encapsulation of internal helper method

Improve encapsulation by changing the internal extension method
ValidateParameters to a private static helper method. This change better
reflects its role as an internal utility.

src/RestSharp/Request/RestRequestExtensions.File.cs [72-86]

-    internal void ValidateParameters() {
+    private static void ValidateParameters(RestRequest request) {
         if (!request.AlwaysSingleFileAsContent) return;
 
         var postParametersExists = request.Parameters.GetContentParameters(request.Method).Any();
         var bodyParametersExists = request.Parameters.Any(p => p.Type == ParameterType.RequestBody);
 
         if (request.AlwaysMultipartFormData)
             throw new ArgumentException("Failed to put file as content because flag AlwaysMultipartFormData is enabled");
 
         if (postParametersExists)
             throw new ArgumentException("Failed to put file as content because POST parameters were added");
 
         if (bodyParametersExists)
             throw new ArgumentException("Failed to put file as content because body parameters were added");
     }
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly proposes changing the internal extension method to a private static helper method to improve encapsulation, which is a good practice for utility functions not intended for public use.

Low
Avoid using the null-forgiving operator

Replace the null-forgiving operator ! with an explicit null check for
ctx.Request.Url to make the test code more robust and provide better error
information.

test/RestSharp.Tests.Shared/Fixtures/Handlers.cs [26]

-var methodName = ctx.Request.Url!.Segments.Last();
+if (ctx.Request.Url is null) throw new InvalidOperationException("Request URL is null");
+var methodName = ctx.Request.Url.Segments.Last();

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 4

__

Why: The suggestion correctly points out the risk of using the null-forgiving operator and proposes a safer alternative with an explicit null check, which improves the robustness of the test code.

Low

No more code suggestions

@github-actions
Copy link

Test Results

   25 files     25 suites   10m 52s ⏱️
  446 tests   446 ✅ 0 💤 0 ❌
2 128 runs  2 128 ✅ 0 💤 0 ❌

Results for commit 109ab58.

@alexeyzimarev alexeyzimarev merged commit 2ae0b6a into dev Nov 12, 2025
9 checks passed
@alexeyzimarev alexeyzimarev deleted the dotnet-10-support branch November 12, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants