Skip to content

Commit

Permalink
Upgrade to .NET 7 and C# 11
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanSaeed committed Nov 9, 2022
1 parent c937af7 commit f8fd671
Show file tree
Hide file tree
Showing 65 changed files with 1,748 additions and 1,239 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
global-json-file: "./global.json"
- name: "Dotnet Tool Restore"
run: dotnet tool restore
Expand Down
3 changes: 2 additions & 1 deletion Benchmarks/Schema.NET.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace Schema.NET.Benchmarks;

public class Program
{
private static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
private static void Main(string[] args) =>
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup Label="Build">
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net5.0;net472</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;net472</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup Label="Build">
<LangVersion>latest</LangVersion>
<LangVersion>preview</LangVersion>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AnalysisLevel>latest</AnalysisLevel>
Expand Down
4 changes: 3 additions & 1 deletion Source/Common/DateTimeToIso8601DateValuesJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Schema.NET;
/// <seealso cref="ValuesJsonConverter" />
public class DateTimeToIso8601DateValuesJsonConverter : ValuesJsonConverter
{
private const string DateFormat = "yyyy-MM-dd";

/// <summary>
/// Writes the object retrieved from <see cref="IValues" /> when one is found.
/// </summary>
Expand All @@ -38,7 +40,7 @@ public override void WriteObject(Utf8JsonWriter writer, object? value, JsonSeria

if (value is DateTime dateTimeType)
{
writer.WriteStringValue(dateTimeType.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
writer.WriteStringValue(dateTimeType.ToString(DateFormat, CultureInfo.InvariantCulture));
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions Source/Common/FastActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ internal static class FastActivator
}

private static Func<T1, object> CreateConstructorDelegate<T1>(ConstructorInfo constructor) => Expression.Lambda<Func<T1, object>>(
Expression.Convert(
Expression.New(constructor, ConstructorParameter<T1>.SingleParameter),
typeof(object)),
ConstructorParameter<T1>.SingleParameter).Compile();
Expression.Convert(
Expression.New(constructor, ConstructorParameter<T1>.SingleParameter),
typeof(object)),
ConstructorParameter<T1>.SingleParameter).Compile();

private static ConstructorInfo? GetConstructorInfo(Type objectType, Type parameter1)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/HashCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override bool Equals(object? obj)
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() =>
#pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
throw new NotSupportedException("Implicitly convert this struct to an int to get the hash code.");
throw new NotSupportedException("Implicitly convert this struct to an int to get the hash code.");
#pragma warning restore CA1065 // Do not raise exceptions in unexpected locations

private static int CombineHashCodes(int h1, int h2)
Expand Down
20 changes: 13 additions & 7 deletions Source/Common/PropertyValueSpecification.Partial.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Schema.NET;

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

Expand All @@ -9,6 +8,13 @@ namespace Schema.NET;
/// </summary>
public partial class PropertyValueSpecification
{
private const string MaxLengthPropertyName = "maxlength=";
private const string MinLengthPropertyName = "minlength=";
private const string NamePropertyName = "name=";
private const string PatternPropertyName = "pattern=";
private const string RequiredPropertyName = "required";
private const char Space = ' ';

/// <summary>
/// Returns a <see cref="string" /> that represents the short hand representation of this instance.
/// See https://schema.org/docs/actions.html#part-3.
Expand All @@ -22,35 +28,35 @@ public override string ToString()

if (this.ValueMaxLength.First() is double maxLength)
{
stringBuilder.Append("maxlength=");
stringBuilder.Append(MaxLengthPropertyName);
stringBuilder.Append(maxLength);
}

if (this.ValueMinLength.First() is double minLength)
{
AppendSpace(stringBuilder);
stringBuilder.Append("minlength=");
stringBuilder.Append(MinLengthPropertyName);
stringBuilder.Append(minLength);
}

if (this.ValueName.First() is string name)
{
AppendSpace(stringBuilder);
stringBuilder.Append("name=");
stringBuilder.Append(NamePropertyName);
stringBuilder.Append(name);
}

if (this.ValuePattern.First() is string pattern)
{
AppendSpace(stringBuilder);
stringBuilder.Append("pattern=");
stringBuilder.Append(PatternPropertyName);
stringBuilder.Append(pattern);
}

if (this.ValueRequired.First() is true)
{
AppendSpace(stringBuilder);
stringBuilder.Append("required");
stringBuilder.Append(RequiredPropertyName);
}

return stringBuilder.ToString();
Expand All @@ -60,7 +66,7 @@ private static void AppendSpace(StringBuilder stringBuilder)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(' ');
stringBuilder.Append(Space);
}
}
}
22 changes: 21 additions & 1 deletion Source/Common/SchemaEnumJsonConverter{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Schema.NET;
/// <summary>
/// Converts a Schema enumeration to and from JSON.
/// </summary>
/// <typeparam name="T">The enum type to convert</typeparam>
/// <typeparam name="T">The enumeration type to convert.</typeparam>
public class SchemaEnumJsonConverter<T> : JsonConverter<T>
where T : struct, Enum
{
Expand Down Expand Up @@ -41,11 +41,21 @@ public SchemaEnumJsonConverter()
/// <returns>The enumeration value.</returns>
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(typeToConvert);
ArgumentNullException.ThrowIfNull(options);
#else
if (typeToConvert is null)
{
throw new ArgumentNullException(nameof(typeToConvert));
}

if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
#endif

var valueString = reader.GetString();
if (EnumHelper.TryParseEnumFromSchemaUri(typeToConvert, valueString, out var result))
{
Expand All @@ -63,11 +73,21 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
/// <param name="options">The JSON serializer options.</param>
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(writer);
ArgumentNullException.ThrowIfNull(options);
#else
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}

if (options is null)
{
throw new ArgumentNullException(nameof(options));
}
#endif

writer.WriteStringValue(this.valueNameMap[value]);
}
}
4 changes: 2 additions & 2 deletions Source/Common/SchemaSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Schema.NET;

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;

Expand Down Expand Up @@ -32,7 +32,7 @@ static SchemaSerializer()
{
AllowTrailingCommas = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};

HtmlEscapedSerializationSettings = new JsonSerializerOptions
Expand Down
7 changes: 0 additions & 7 deletions Source/Common/Values{T1,T2,T3,T4,T5,T6,T7}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,43 +209,36 @@ public Values(IEnumerable<object?> items)
if (item is T7 itemT7)
{
items7 ??= new List<T7>();

items7.Add(itemT7);
}
else if (item is T6 itemT6)
{
items6 ??= new List<T6>();

items6.Add(itemT6);
}
else if (item is T5 itemT5)
{
items5 ??= new List<T5>();

items5.Add(itemT5);
}
else if (item is T4 itemT4)
{
items4 ??= new List<T4>();

items4.Add(itemT4);
}
else if (item is T3 itemT3)
{
items3 ??= new List<T3>();

items3.Add(itemT3);
}
else if (item is T2 itemT2)
{
items2 ??= new List<T2>();

items2.Add(itemT2);
}
else if (item is T1 itemT1)
{
items1 ??= new List<T1>();

items1.Add(itemT1);
}
}
Expand Down
6 changes: 0 additions & 6 deletions Source/Common/Values{T1,T2,T3,T4,T5,T6}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,37 +173,31 @@ public Values(IEnumerable<object?> items)
if (item is T6 itemT6)
{
items6 ??= new List<T6>();

items6.Add(itemT6);
}
else if (item is T5 itemT5)
{
items5 ??= new List<T5>();

items5.Add(itemT5);
}
else if (item is T4 itemT4)
{
items4 ??= new List<T4>();

items4.Add(itemT4);
}
else if (item is T3 itemT3)
{
items3 ??= new List<T3>();

items3.Add(itemT3);
}
else if (item is T2 itemT2)
{
items2 ??= new List<T2>();

items2.Add(itemT2);
}
else if (item is T1 itemT1)
{
items1 ??= new List<T1>();

items1.Add(itemT1);
}
}
Expand Down
4 changes: 0 additions & 4 deletions Source/Common/Values{T1,T2,T3,T4}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,21 @@ public Values(IEnumerable<object?> items)
if (item is T4 itemT4)
{
items4 ??= new List<T4>();

items4.Add(itemT4);
}
else if (item is T3 itemT3)
{
items3 ??= new List<T3>();

items3.Add(itemT3);
}
else if (item is T2 itemT2)
{
items2 ??= new List<T2>();

items2.Add(itemT2);
}
else if (item is T1 itemT1)
{
items1 ??= new List<T1>();

items1.Add(itemT1);
}
}
Expand Down
3 changes: 0 additions & 3 deletions Source/Common/Values{T1,T2,T3}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,16 @@ public Values(IEnumerable<object> items)
if (item is T3 itemT3)
{
items3 ??= new List<T3>();

items3.Add(itemT3);
}
else if (item is T2 itemT2)
{
items2 ??= new List<T2>();

items2.Add(itemT2);
}
else if (item is T1 itemT1)
{
items1 ??= new List<T1>();

items1.Add(itemT1);
}
}
Expand Down
6 changes: 0 additions & 6 deletions Source/Common/Values{T1,T2}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ public Values(IEnumerable<object?> items)
if (item is T2 itemT2)
{
items2 ??= new List<T2>();

items2.Add(itemT2);
}
else if (item is T1 itemT1)
{
items1 ??= new List<T1>();

items1.Add(itemT1);
}
}
Expand Down Expand Up @@ -117,8 +115,6 @@ public Values(IEnumerable<object?> items)
/// </summary>
public OneOrMany<T2> Value2 { get; }

#pragma warning disable CA1002 // Do not expose generic lists
#pragma warning disable CA2225 // Operator overloads have named alternates
/// <summary>
/// Performs an implicit conversion from <typeparamref name="T1"/> to <see cref="Values{T1,T2}"/>.
/// </summary>
Expand Down Expand Up @@ -228,8 +224,6 @@ public Values(IEnumerable<object?> items)
/// The result of the conversion.
/// </returns>
public static implicit operator List<T2>(Values<T1, T2> values) => values.Value2.ToList();
#pragma warning restore CA2225 // Operator overloads have named alternates
#pragma warning restore CA1002 // Do not expose generic lists

/// <summary>
/// Implements the operator ==.
Expand Down
2 changes: 1 addition & 1 deletion Source/Schema.NET.Pending/Schema.NET.Pending.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
<IncludePendingSchemaObjects>True</IncludePendingSchemaObjects>
Expand Down
2 changes: 1 addition & 1 deletion Source/Schema.NET/Schema.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Build">
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0;netcoreapp3.1;netstandard2.0;net472;net461</TargetFrameworks>
<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
<IncludePendingSchemaObjects>False</IncludePendingSchemaObjects>
Expand Down
Loading

0 comments on commit f8fd671

Please sign in to comment.