Skip to content

Commit

Permalink
Remove net45, net461, netcoreapp3.1 support (#111)
Browse files Browse the repository at this point in the history
Also removes stragling `netstandard1.1` references (#108)
  • Loading branch information
MingweiSamuel committed Apr 4, 2024
1 parent 47e4ddf commit 43a9e03
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 151 deletions.
2 changes: 1 addition & 1 deletion src/Camille.Core/Camille.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.csproj.xml" />
<PropertyGroup>
<TargetFrameworks>net45;net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<PackageId>Camille.Core</PackageId>
<RootNamespace>Camille.Core</RootNamespace>
<Description>Core utilities for Camille packages.</Description>
Expand Down
55 changes: 0 additions & 55 deletions src/Camille.Core/JsonHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,6 @@

namespace Camille.Core
{
#if USE_NEWTONSOFT
public static class JsonHandler
{
/// <summary>Settings singleton.</summary>
private static readonly Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings =
new Newtonsoft.Json.JsonSerializerSettings()
{
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
Converters = new[] { new CustomIntConverter() },
};

/// <summary>Int32 converter which is able to read integers with decimal points "123.0".</summary>
private class CustomIntConverter : Newtonsoft.Json.JsonConverter
{
public override bool CanConvert(Type objectType) { return typeof(int) == objectType; }

public override object ReadJson(
Newtonsoft.Json.JsonReader reader, Type objectType,
object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
if (Newtonsoft.Json.JsonToken.Float == reader.TokenType)
{
var doubleVal = serializer.Deserialize<double>(reader);
var intVal = (int) doubleVal;
if (doubleVal == intVal)
return intVal;
throw new Newtonsoft.Json.JsonException($"Cannot parse number as int: {doubleVal}.");
}
return (int) serializer.Deserialize<long>(reader);
}

public override bool CanWrite { get { return false; } }

public override void WriteJson(
Newtonsoft.Json.JsonWriter writer, object value,
Newtonsoft.Json.JsonSerializer serializer)
{
throw new NotImplementedException();
}
}

public static T Deserialize<T>(string content)
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(content, jsonSerializerSettings);
}

public static string Serialize<T>(T value)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(value, jsonSerializerSettings);
}
}
#elif USE_SYSTEXTJSON
public static class JsonHandler
{
/// <summary>Options singleton.</summary>
Expand Down Expand Up @@ -96,7 +44,4 @@ public static string Serialize<T>(T value)
return System.Text.Json.JsonSerializer.Serialize(value, jsonOptions);
}
}
#else
#error One of USE_NEWTONSOFT or USE_SYSTEXTJSON must be set.
#endif
}
2 changes: 1 addition & 1 deletion src/Camille.Enums/Camille.Enums.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.csproj.xml" />
<PropertyGroup>
<TargetFrameworks>net45;net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<PackageId>Camille.Enums</PackageId>
<RootNamespace>Camille.Enums</RootNamespace>
<Description>Enums for League of Legends and other Riot Games games.</Description>
Expand Down
4 changes: 0 additions & 4 deletions src/Camille.Enums/gen/GameMode.cs.dt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ namespace Camille.Enums
/// <summary>
/// GameModes enum based on gameModes.json.
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum GameMode
{
{{
Expand Down
4 changes: 0 additions & 4 deletions src/Camille.Enums/gen/GameType.cs.dt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ namespace Camille.Enums
/// <summary>
/// GameTypes enum based on gameTypes.json.
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum GameType
{
{{
Expand Down
4 changes: 0 additions & 4 deletions src/Camille.Enums/gen/QueueType.cs.dt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ using System.ComponentModel.DataAnnotations;

namespace Camille.Enums
{
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
/// <summary>
/// QueueType enum based on queueTypes.json.
/// </summary>
Expand Down
16 changes: 0 additions & 16 deletions src/Camille.Enums/gen/Route.cs.dt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ namespace Camille.Enums
/// <summary>
/// Regional routes, used in tournament services, Legends of Runeterra (LoR), and some other endpoints.
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum RegionalRoute: byte
{
{{
Expand Down Expand Up @@ -46,11 +42,7 @@ namespace Camille.Enums
/// <summary>
/// Platform routes for League of Legends (LoL), Teanfight Tactics (TFT), and Legends of Runeterra (LoR).
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum PlatformRoute: byte
{
{{
Expand Down Expand Up @@ -79,11 +71,7 @@ namespace Camille.Enums
/// <summary>
/// Platform routes for Valorant.
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum ValPlatformRoute: byte
{
{{
Expand Down Expand Up @@ -113,11 +101,7 @@ namespace Camille.Enums
/// Tournament regions for League of Legends (LoL) used in TournamentStubV4 and TournamentV4's
/// RegisterProviderData method.
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum TournamentRegion: byte
{
{{
Expand Down
4 changes: 0 additions & 4 deletions src/Camille.Enums/src/Division.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace Camille.Enums
{
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum Division : byte
{
/// <summary>
Expand Down
4 changes: 0 additions & 4 deletions src/Camille.Enums/src/Locale.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
namespace Camille.Enums
{
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum Locale
{
en_US,
Expand Down
8 changes: 1 addition & 7 deletions src/Camille.Enums/src/Tier.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;

namespace Camille.Enums
namespace Camille.Enums
{
/// <summary>
/// Contains tier names (CHALLENGER, MASTER, etc.)
/// </summary>
#if USE_NEWTONSOFT
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
#elif USE_SYSTEXTJSON
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
#endif
public enum Tier : byte
{
CHALLENGER = 20,
Expand Down
2 changes: 1 addition & 1 deletion src/Camille.LolGame/Camille.LolGame.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.csproj.xml" />
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<PackageId>Camille.LolGame</PackageId>
<RootNamespace>Camille.LolGame</RootNamespace>
<Description>League of Legends Live (In-Game) Client Data API library</Description>
Expand Down
16 changes: 5 additions & 11 deletions src/Camille.LolGame/src/LolGameErrorMessage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#if USE_NEWTONSOFT
using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
#elif USE_SYSTEXTJSON
using JsonPropertyAttribute = System.Text.Json.Serialization.JsonPropertyNameAttribute;
#else
#error One of USE_NEWTONSOFT or USE_SYSTEXTJSON must be set.
#endif
using System.Text.Json.Serialization;

namespace Camille.LolGame
{
Expand All @@ -14,20 +8,20 @@ public class LolGameErrorMessage
public LolGameErrorMessage() { }
#nullable restore

[JsonProperty("errorCode")]
[JsonPropertyName("errorCode")]
public string ErrorCode { get; set; }

[JsonProperty("httpStatus")]
[JsonPropertyName("httpStatus")]
public int HttpStatus { get; set; }

[JsonProperty("implementationDetails")]
[JsonPropertyName("implementationDetails")]
public object ImplementationDetails { get; set; }

/// <summary>
/// If this is set to "Spectator mode doesn't currently support this feature" then you are calling a
/// active-player endpoint while spectating.
/// </summary>
[JsonProperty("message")]
[JsonPropertyName("message")]
public string Message { get; set; }

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion src/Camille.RiotGames/Camille.RiotGames.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\common.csproj.xml" />
<PropertyGroup>
<TargetFrameworks>net45;net461;netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<PackageId>Camille.RiotGames</PackageId>
<RootNamespace>Camille.RiotGames</RootNamespace>
<Description>Riot Games API library. Fully rate limited, automatic retrying, thread-safe. Up-to-date nightlies.</Description>
Expand Down
31 changes: 4 additions & 27 deletions src/common.csproj.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,11 @@
<None Include="$(SolutionDir)\LICENSE-APACHE.txt" Pack="true" PackagePath="\" />
</ItemGroup>

<!-- Include RiotCertificateUtils for LCU or In-Game APIs. -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">
<!-- Include RiotCertificateUtils for LolGame (In-Game) API. (Also used by LCU, but LCU support was removed. -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">
<DefineConstants>$(DefineConstants);INCLUDE_RIOTCERTIFICATEUTILS</DefineConstants>
</PropertyGroup>

<!-- Camille using Newtonsoft.Json. -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<DefineConstants>$(DefineConstants);USE_NEWTONSOFT</DefineConstants>
</PropertyGroup>
<!-- Camille using System.Text.Json. -->
<PropertyGroup Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net6.0' Or '$(TargetFramework)' == 'net7.0'">
<DefineConstants>$(DefineConstants);USE_SYSTEXTJSON</DefineConstants>
</PropertyGroup>
<!--
HttpRequestMessage.Options in net 5/6/7.
https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httprequestoptions?view=net-5.0
Expand All @@ -82,27 +74,12 @@
<DefineConstants>$(DefineConstants);USE_HTTPREQUESTMESSAGE_OPTIONS;USE_HTTPCONTENT_READASSTRINGASYNC_CANCELLATIONTOKEN</DefineConstants>
</PropertyGroup>

<!-- Newtonsoft from NuGet. -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1' Or '$(TargetFramework)' == 'net45'">
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>
<!-- Nullable attributes from NuGet. -->
<!--<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1' Or '$(TargetFramework)' == 'net45'">
<PackageReference Include="Nullable" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime;build;native;contentfiles;analyzers;buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>-->
<!-- System.Net.Http from Nuget. -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1' Or '$(TargetFramework)' == 'net45' Or '$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<!-- System.Text.Json from NuGet, for tagets stricly below net6.0. -->
<ItemGroup Condition="'$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'netstandard2.1' Or '$(TargetFramework)' == 'netcoreapp3.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Text.Json" Version="6.0.0" />
</ItemGroup>
<!-- System.ComponentModel.DataAnnotations from NuGet. -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1' Or '$(TargetFramework)' == 'net45' Or '$(TargetFramework)' == 'net461' Or '$(TargetFramework)' == 'netstandard2.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0" />
</ItemGroup>

Expand Down
11 changes: 1 addition & 10 deletions srcgen/dataClasses.dt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@

using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

{{= it.usings.join('\r\n') }}

#if USE_NEWTONSOFT
using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
using JsonExtensionDataAttribute = Newtonsoft.Json.JsonExtensionDataAttribute;
#elif USE_SYSTEXTJSON
using JsonPropertyAttribute = System.Text.Json.Serialization.JsonPropertyNameAttribute;
using JsonExtensionDataAttribute = System.Text.Json.Serialization.JsonExtensionDataAttribute;
#else
#error One of USE_NEWTONSOFT or USE_SYSTEXTJSON must be set.
#endif

// ReSharper disable InconsistentNaming

{{/* DTOs */}}
Expand Down
2 changes: 1 addition & 1 deletion srcgen/dotUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function replaceEnumCasts(input) {
}

function formatJsonProperty(name) {
return `[JsonProperty("${name}")]`;
return `[JsonPropertyName("${name}")]`;
}

function formatQueryParamStringify(expr, prop) {
Expand Down

0 comments on commit 43a9e03

Please sign in to comment.