Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: Event File
path: ${{ github.event_path }}
Expand All @@ -28,21 +28,28 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Setup .NET
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
-
name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x
dotnet-quality: 'preview'
-
name: Run tests
run: dotnet test -c Debug -f ${{ matrix.dotnet }}
-
name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: Test Results Windows ${{ matrix.dotnet }}
path: |
Expand All @@ -59,21 +66,28 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
-
name: Setup .NET
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
-
name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x
dotnet-quality: 'preview'
-
name: Run tests
run: dotnet test -f ${{ matrix.dotnet }}
-
name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: Test Results Ubuntu ${{ matrix.dotnet }}
path: |
Expand Down
17 changes: 12 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<PropertyGroup Label="Package versions for .NET 8" Condition="$(TargetFramework) == 'net8.0'">
<MicrosoftTestHostVer>8.0.3</MicrosoftTestHostVer>
<PropertyGroup Label="Package versions for .NET 10" Condition="'$(TargetFramework)' == 'net10.0'">
<MicrosoftTestHostVer>10.0.0-rc.2.25502.107</MicrosoftTestHostVer>
<SystemTextJsonVer>10.0.0-rc.2.25502.107</SystemTextJsonVer>
</PropertyGroup>
<PropertyGroup Label="Package versions for .NET 9" Condition="$(TargetFramework) == 'net9.0'">
<MicrosoftTestHostVer>9.0.0</MicrosoftTestHostVer>
<PropertyGroup Label="Package versions for .NET 9" Condition="'$(TargetFramework)' == 'net9.0'">
<MicrosoftTestHostVer>9.0.10</MicrosoftTestHostVer>
</PropertyGroup>
<PropertyGroup Label="Package versions for .NET 8" Condition="'$(TargetFramework)' == 'net8.0'">
<MicrosoftTestHostVer>8.0.21</MicrosoftTestHostVer>
</PropertyGroup>
<PropertyGroup Label="Package versions for pre-.NET 10" Condition="'$(TargetFramework)' != 'net10.0'">
<SystemTextJsonVer>9.0.10</SystemTextJsonVer>
</PropertyGroup>
<ItemGroup Label="Runtime dependencies">
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageVersion Include="CsvHelper" Version="33.0.1"/>
<PackageVersion Include="System.Text.Json" Version="9.0.0"/>
<PackageVersion Include="System.Text.Json" Version="$(SystemTextJsonVer)"/>
</ItemGroup>
<ItemGroup Label="Compile dependencies">
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void GlobalSetup() {
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
var dateTime = DateTime.Parse("01/01/2013 03:03:12");

_data = new Data(@string, int.MaxValue, strings, ints, dateTime, strings);
_data = new(@string, int.MaxValue, strings, ints, dateTime, strings);
}

[Benchmark(Baseline = true)]
Expand Down
26 changes: 14 additions & 12 deletions gen/SourceGenerator/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
namespace SourceGenerator;

static class Extensions {
public static IEnumerable<ClassDeclarationSyntax> FindClasses(this Compilation compilation, Func<ClassDeclarationSyntax, bool> predicate)
=> compilation.SyntaxTrees
.Select(tree => compilation.GetSemanticModel(tree))
.SelectMany(model => model.SyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>())
.Where(predicate);
extension(Compilation compilation) {
public IEnumerable<ClassDeclarationSyntax> FindClasses(Func<ClassDeclarationSyntax, bool> predicate)
=> compilation.SyntaxTrees
.Select(tree => compilation.GetSemanticModel(tree))
.SelectMany(model => model.SyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>())
.Where(predicate);

public static IEnumerable<ClassDeclarationSyntax> FindAnnotatedClasses(this Compilation compilation, string attributeName, bool strict) {
return compilation.FindClasses(
syntax => syntax.AttributeLists.Any(list => list.Attributes.Any(CheckAttribute))
);
public IEnumerable<ClassDeclarationSyntax> FindAnnotatedClasses(string attributeName, bool strict) {
return compilation.FindClasses(
syntax => syntax.AttributeLists.Any(list => list.Attributes.Any(CheckAttribute))
);

bool CheckAttribute(AttributeSyntax attr) {
var name = attr.Name.ToString();
return strict ? name == attributeName : name.StartsWith(attributeName);
bool CheckAttribute(AttributeSyntax attr) {
var name = attr.Name.ToString();
return strict ? name == attributeName : name.StartsWith(attributeName);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'RestSharp.sln'))\props\Common.props"/>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net471;net48;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net471;net48;net8.0;net9.0;net10.0</TargetFrameworks>
<PackageIcon>restsharp.png</PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://restsharp.dev</PackageProjectUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/RestSharp.Serializers.CsvHelper/CsvHelperSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CsvHelperSerializer(CsvConfiguration configuration) : IDeserializer

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

public CsvHelperSerializer() : this(new CsvConfiguration(CultureInfo.InvariantCulture)) { }
public CsvHelperSerializer() : this(new(CultureInfo.InvariantCulture)) { }

public T? Deserialize<T>(RestResponse response) {
try {
Expand Down
8 changes: 5 additions & 3 deletions src/RestSharp.Serializers.CsvHelper/RestClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ namespace RestSharp.Serializers.CsvHelper;

[PublicAPI]
public static class RestClientExtensions {
public static SerializerConfig UseCsvHelper(this SerializerConfig config) => config.UseSerializer<CsvHelperSerializer>();
extension(SerializerConfig config) {
public SerializerConfig UseCsvHelper() => config.UseSerializer<CsvHelperSerializer>();

public static SerializerConfig UseCsvHelper(this SerializerConfig config, CsvConfiguration configuration)
=> config.UseSerializer(() => new CsvHelperSerializer(configuration));
public SerializerConfig UseCsvHelper(CsvConfiguration configuration)
=> config.UseSerializer(() => new CsvHelperSerializer(configuration));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class JsonNetSerializer : IRestSerializer, ISerializer, IDeserializer {
public string? Serialize(object? obj) {
if (obj == null) return null;

using var buffer = _writerBuffer ??= new WriterBuffer(_serializer);
using var buffer = _writerBuffer ??= new(_serializer);

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

Expand Down
27 changes: 14 additions & 13 deletions src/RestSharp.Serializers.NewtonsoftJson/RestClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ namespace RestSharp.Serializers.NewtonsoftJson;

[PublicAPI]
public static class RestClientExtensions {
/// <summary>
/// Use Newtonsoft.Json serializer with default settings
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public static SerializerConfig UseNewtonsoftJson(this SerializerConfig config) => config.UseSerializer(() => new JsonNetSerializer());
extension(SerializerConfig config) {
/// <summary>
/// Use Newtonsoft.Json serializer with default settings
/// </summary>
/// <returns></returns>
public SerializerConfig UseNewtonsoftJson() => config.UseSerializer(() => new JsonNetSerializer());

/// <summary>
/// Use Newtonsoft.Json serializer with custom settings
/// </summary>
/// <param name="config"></param>
/// <param name="settings">Newtonsoft.Json serializer settings</param>
/// <returns></returns>
public static SerializerConfig UseNewtonsoftJson(this SerializerConfig config, JsonSerializerSettings settings)
=> config.UseSerializer(() => new JsonNetSerializer(settings));
/// <summary>
/// Use Newtonsoft.Json serializer with custom settings
/// </summary>
/// <param name="settings">Newtonsoft.Json serializer settings</param>
/// <returns></returns>
public SerializerConfig UseNewtonsoftJson(JsonSerializerSettings settings)
=> config.UseSerializer(() => new JsonNetSerializer(settings));
}
}
5 changes: 2 additions & 3 deletions src/RestSharp.Serializers.NewtonsoftJson/WriterBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

using System.Globalization;
using System.Text;

namespace RestSharp.Serializers.NewtonsoftJson;

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

public WriterBuffer(JsonSerializer jsonSerializer) {
_stringWriter = new StringWriter(new StringBuilder(256), CultureInfo.InvariantCulture);
_stringWriter = new(new(256), CultureInfo.InvariantCulture);

_jsonTextWriter = new JsonTextWriter(_stringWriter) {
_jsonTextWriter = new(_stringWriter) {
Formatting = jsonSerializer.Formatting, CloseOutput = false
};
}
Expand Down
12 changes: 3 additions & 9 deletions src/RestSharp.Serializers.Xml/SerializeAsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ namespace RestSharp.Serializers;
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, Inherited = false)]
public sealed class SerializeAsAttribute : Attribute {
public SerializeAsAttribute() {
NameStyle = NameStyle.AsIs;
Index = int.MaxValue;
Culture = CultureInfo.InvariantCulture;
}

/// <summary>
/// The name to use for the serialized element
/// </summary>
Expand All @@ -51,17 +45,17 @@ public SerializeAsAttribute() {
/// <summary>
/// The culture to use when serializing
/// </summary>
public CultureInfo Culture { get; set; }
public CultureInfo Culture { get; set; } = CultureInfo.InvariantCulture;

/// <summary>
/// Transforms the casing of the name based on the selected value.
/// </summary>
public NameStyle NameStyle { get; set; }
public NameStyle NameStyle { get; set; } = NameStyle.AsIs;

/// <summary>
/// The order to serialize the element. Default is int.MaxValue.
/// </summary>
public int Index { get; set; }
public int Index { get; set; } = int.MaxValue;

/// <summary>
/// Called by the attribute when NameStyle is speficied
Expand Down
8 changes: 3 additions & 5 deletions src/RestSharp.Serializers.Xml/XmlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
namespace RestSharp.Serializers.Xml;

public class XmlDeserializer : IXmlDeserializer, IWithRootElement, IWithDateFormat {
public XmlDeserializer() => Culture = CultureInfo.InvariantCulture;

public CultureInfo Culture { get; set; }
public CultureInfo Culture { get; set; } = CultureInfo.InvariantCulture;

public string? RootElement { get; set; }

Expand Down Expand Up @@ -75,7 +73,7 @@ static void RemoveNamespace(XDocument xdoc) {
a => a.IsNamespaceDeclaration
? null
: a.Name.Namespace != XNamespace.None
? new XAttribute(XNamespace.None.GetName(a.Name.LocalName), a.Value)
? new(XNamespace.None.GetName(a.Name.LocalName), a.Value)
: a
)
);
Expand Down Expand Up @@ -227,7 +225,7 @@ protected virtual object Map(object x, XElement? root) {
else if (asType == typeof(Guid)) {
var raw = value.ToString();

value = string.IsNullOrEmpty(raw) ? Guid.Empty : new Guid(value.ToString()!);
value = string.IsNullOrEmpty(raw) ? Guid.Empty : new(value.ToString()!);

prop.SetValue(x, value, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
namespace RestSharp.Authenticators.OAuth.Extensions;

static class StringExtensions {
public static bool EqualsIgnoreCase(this string left, string right) => string.Equals(left, right, StringComparison.InvariantCultureIgnoreCase);
extension(string left) {
public bool EqualsIgnoreCase(string right) => string.Equals(left, right, StringComparison.InvariantCultureIgnoreCase);

public static string Then(this string input, string value) => string.Concat(input, value);
public string Then(string value) => string.Concat(left, value);

public static Uri AsUri(this string value) => new(value);
public Uri AsUri() => new(left);

public static byte[] GetBytes(this string input) => Encoding.UTF8.GetBytes(input);
public byte[] GetBytes() => Encoding.UTF8.GetBytes(left);

public static string PercentEncode(this string s) => string.Join("", s.GetBytes().Select(x => $"%{x:X2}"));
public string PercentEncode() => string.Join("", left.GetBytes().Select(x => $"%{x:X2}"));
}
}
4 changes: 2 additions & 2 deletions src/RestSharp/Authenticators/OAuth/OAuthTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static OAuthTools() {
var bytes = new byte[4];

Rng.GetBytes(bytes);
Random = new Random(BitConverter.ToInt32(bytes, 0));
Random = new(BitConverter.ToInt32(bytes, 0));
}

/// <summary>
Expand All @@ -60,7 +60,7 @@ public static string GetNonce() {
for (var i = 0; i < nonce.Length; i++) nonce[i] = chars[Random.Next(0, chars.Length)];
}

return new string(nonce);
return new(nonce);
}

/// <summary>
Expand Down
Loading
Loading