Skip to content

Commit

Permalink
Add NRT in all libraries (#1637)
Browse files Browse the repository at this point in the history
* Add NRT in all libraries

* fx

* skip tests

---------

Co-authored-by: Rico Suter <rico.suter@buhlergroup.com>
  • Loading branch information
RicoSuter and Rico Suter committed Oct 14, 2023
1 parent ebd165d commit 85fdd00
Show file tree
Hide file tree
Showing 103 changed files with 1,289 additions and 1,319 deletions.
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
59 changes: 30 additions & 29 deletions src/NJsonSchema.Benchmark/NJsonSchema.Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<NoWarn>$(NoWarn),xUnit1013</NoWarn>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="*.json" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<NoWarn>$(NoWarn),xUnit1013</NoWarn>
<SignAssembly>false</SignAssembly>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NBench" Version="2.0.1" />
<PackageReference Include="Pro.NBench.xUnit" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="*.json" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NBench" Version="2.0.1" />
<PackageReference Include="Pro.NBench.xUnit" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj" />
<ProjectReference Include="..\NJsonSchema.CodeGeneration.TypeScript\NJsonSchema.CodeGeneration.TypeScript.csproj" />
<ProjectReference Include="..\NJsonSchema.NewtonsoftJson\NJsonSchema.NewtonsoftJson.csproj" />
<ProjectReference Include="..\NJsonSchema.Tests\NJsonSchema.Tests.csproj" />
<ProjectReference Include="..\NJsonSchema\NJsonSchema.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj" />
<ProjectReference Include="..\NJsonSchema.CodeGeneration.TypeScript\NJsonSchema.CodeGeneration.TypeScript.csproj" />
<ProjectReference Include="..\NJsonSchema.NewtonsoftJson\NJsonSchema.NewtonsoftJson.csproj" />
<ProjectReference Include="..\NJsonSchema.Tests\NJsonSchema.Tests.csproj" />
<ProjectReference Include="..\NJsonSchema\NJsonSchema.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn),1587,1998,1591,618,SYSLIB0012</NoWarn>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn),1587,1998,1591,618,SYSLIB0012</NoWarn>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<Content Include="References\*.json" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<Content Include="References\*.json" CopyToOutputDirectory="Always" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Condition="'$(TargetFramework)' == 'net6.0'" Include="System.ComponentModel.Annotations" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Condition="'$(TargetFramework)' == 'net6.0'" Include="System.ComponentModel.Annotations" Version="4.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj" />
<ProjectReference Include="..\NJsonSchema.NewtonsoftJson\NJsonSchema.NewtonsoftJson.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj" />
<ProjectReference Include="..\NJsonSchema.NewtonsoftJson\NJsonSchema.NewtonsoftJson.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/NJsonSchema.CodeGeneration.CSharp/CSharpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private CodeArtifact GenerateClass(JsonSchema schema, string typeName)
private static void RenamePropertyWithSameNameAsClass(string typeName, IEnumerable<PropertyModel> properties)
{
var propertyModels = properties as PropertyModel[] ?? properties.ToArray();
PropertyModel propertyWithSameNameAsClass = null;
PropertyModel? propertyWithSameNameAsClass = null;
foreach (var p in propertyModels)
{
if (p.PropertyName == typeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public CSharpGeneratorSettings()
public string PropertySetterAccessModifier { get; set; }

/// <summary>Gets or sets the custom Json.NET converters (class names) which are registered for serialization and deserialization.</summary>
public string[] JsonConverters { get; set; }
public string[]? JsonConverters { get; set; }

/// <summary>Gets or sets a value indicating whether to remove the setter for non-nullable array properties (default: false).</summary>
public bool GenerateImmutableArrayProperties { get; set; }
Expand All @@ -122,7 +122,7 @@ public CSharpGeneratorSettings()
public bool HandleReferences { get; set; }

/// <summary>Gets or sets the name of a static method which is called to transform the JsonSerializerSettings (for Newtonsoft.Json) or the JsonSerializerOptions (for System.Text.Json) used in the generated ToJson()/FromJson() methods (default: null).</summary>
public string JsonSerializerSettingsTransformationMethod { get; set; }
public string? JsonSerializerSettingsTransformationMethod { get; set; }

/// <summary>Gets or sets a value indicating whether to render ToJson() and FromJson() methods (default: false).</summary>
public bool GenerateJsonMethods { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class CSharpJsonSerializerGenerator
/// <param name="settings">The settings.</param>
/// <param name="additionalJsonConverters">The additional JSON converters.</param>
/// <returns>The code.</returns>
public static string GenerateJsonSerializerParameterCode(CSharpGeneratorSettings settings, IEnumerable<string> additionalJsonConverters)
public static string GenerateJsonSerializerParameterCode(CSharpGeneratorSettings settings, IEnumerable<string>? additionalJsonConverters)
{
var jsonConverters = GetJsonConverters(settings, additionalJsonConverters);
var hasJsonConverters = jsonConverters.Any();
Expand All @@ -31,14 +31,14 @@ public static string GenerateJsonSerializerParameterCode(CSharpGeneratorSettings
/// <param name="settings">The settings.</param>
/// <param name="additionalJsonConverters">The additional JSON converters.</param>
/// <returns>The code.</returns>
public static string GenerateJsonConvertersArrayCode(CSharpGeneratorSettings settings, IEnumerable<string> additionalJsonConverters)
public static string GenerateJsonConvertersArrayCode(CSharpGeneratorSettings settings, IEnumerable<string>? additionalJsonConverters)
{
var jsonConverters = GetJsonConverters(settings, additionalJsonConverters);

return GenerateConverters(jsonConverters, settings.JsonLibrary);
}

private static List<string> GetJsonConverters(CSharpGeneratorSettings settings, IEnumerable<string> additionalJsonConverters)
private static List<string> GetJsonConverters(CSharpGeneratorSettings settings, IEnumerable<string>? additionalJsonConverters)
{
return (settings.JsonConverters ?? Array.Empty<string>()).Concat(additionalJsonConverters ?? Array.Empty<string>()).ToList();
}
Expand Down
12 changes: 6 additions & 6 deletions src/NJsonSchema.CodeGeneration.CSharp/CSharpTypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public CSharpTypeResolver(CSharpGeneratorSettings settings)
/// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver"/> class.</summary>
/// <param name="settings">The generator settings.</param>
/// <param name="exceptionSchema">The exception type schema.</param>
public CSharpTypeResolver(CSharpGeneratorSettings settings, JsonSchema exceptionSchema)
public CSharpTypeResolver(CSharpGeneratorSettings settings, JsonSchema? exceptionSchema)
: base(settings)
{
Settings = settings;
ExceptionSchema = exceptionSchema;
}

/// <summary>Gets the exception schema.</summary>
public JsonSchema ExceptionSchema { get; }
public JsonSchema? ExceptionSchema { get; }

/// <summary>Gets the generator settings.</summary>
public CSharpGeneratorSettings Settings { get; }
Expand All @@ -42,7 +42,7 @@ public CSharpTypeResolver(CSharpGeneratorSettings settings, JsonSchema exception
/// <param name="isNullable">Specifies whether the given type usage is nullable.</param>
/// <param name="typeNameHint">The type name hint to use when generating the type and the type name is missing.</param>
/// <returns>The type name.</returns>
public override string Resolve(JsonSchema schema, bool isNullable, string typeNameHint)
public override string Resolve(JsonSchema schema, bool isNullable, string? typeNameHint)
{
return Resolve(schema, isNullable, typeNameHint, true);
}
Expand All @@ -53,7 +53,7 @@ public override string Resolve(JsonSchema schema, bool isNullable, string typeNa
/// <param name="typeNameHint">The type name hint to use when generating the type and the type name is missing.</param>
/// <param name="checkForExistingSchema">Checks whether a named schema is already registered.</param>
/// <returns>The type name.</returns>
public string Resolve(JsonSchema schema, bool isNullable, string typeNameHint, bool checkForExistingSchema)
public string Resolve(JsonSchema schema, bool isNullable, string? typeNameHint, bool checkForExistingSchema)
{
if (schema == null)
{
Expand Down Expand Up @@ -158,7 +158,7 @@ protected override bool IsDefinitionTypeSchema(JsonSchema schema)
return base.IsDefinitionTypeSchema(schema);
}

private string ResolveString(JsonSchema schema, bool isNullable, string typeNameHint)
private string ResolveString(JsonSchema schema, bool isNullable, string? typeNameHint)
{
var nullableReferenceType = Settings.GenerateNullableReferenceTypes && isNullable ? "?" : string.Empty;

Expand Down Expand Up @@ -209,7 +209,7 @@ private static string ResolveBoolean(bool isNullable)
return isNullable ? "bool?" : "bool";
}

private string ResolveInteger(JsonSchema schema, bool isNullable, string typeNameHint)
private string ResolveInteger(JsonSchema schema, bool isNullable, string? typeNameHint)
{
if (schema.Format == JsonFormatStrings.Byte)
{
Expand Down
45 changes: 20 additions & 25 deletions src/NJsonSchema.CodeGeneration.CSharp/CSharpValueGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CSharpValueGenerator(CSharpGeneratorSettings settings)
/// <param name="useSchemaDefault">if set to <c>true</c> uses the default value from the schema if available.</param>
/// <param name="typeResolver">The type resolver.</param>
/// <returns>The code.</returns>
public override string GetDefaultValue(JsonSchema schema, bool allowsNull, string targetType, string typeNameHint, bool useSchemaDefault, TypeResolverBase typeResolver)
public override string? GetDefaultValue(JsonSchema schema, bool allowsNull, string targetType, string? typeNameHint, bool useSchemaDefault, TypeResolverBase typeResolver)
{
var value = base.GetDefaultValue(schema, allowsNull, targetType, typeNameHint, useSchemaDefault, typeResolver);
if (value == null)
Expand Down Expand Up @@ -87,32 +87,27 @@ public override string GetDefaultValue(JsonSchema schema, bool allowsNull, strin
/// <param name="value">The value to convert.</param>
/// <param name="format">Optional schema format</param>
/// <returns>The C# number literal.</returns>
public override string GetNumericValue(JsonObjectType type, object value, string format)
public override string GetNumericValue(JsonObjectType type, object value, string? format)
{
if (value != null)
switch (format)
{
switch (format)
{
case JsonFormatStrings.Byte:
return "(byte)" + Convert.ToByte(value).ToString(CultureInfo.InvariantCulture);
case JsonFormatStrings.Integer:
return Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
case JsonFormatStrings.Long:
return Convert.ToInt64(value) + "L";
case JsonFormatStrings.Double:
return ConvertNumberToString(value) + "D";
case JsonFormatStrings.Float:
return ConvertNumberToString(value) + "F";
case JsonFormatStrings.Decimal:
return ConvertNumberToString(value) + "M";
default:
return type.IsInteger() ?
ConvertNumberToString(value) :
ConvertNumberToString(value) + "D";
}
case JsonFormatStrings.Byte:
return "(byte)" + Convert.ToByte(value).ToString(CultureInfo.InvariantCulture);
case JsonFormatStrings.Integer:
return Convert.ToInt32(value).ToString(CultureInfo.InvariantCulture);
case JsonFormatStrings.Long:
return Convert.ToInt64(value) + "L";
case JsonFormatStrings.Double:
return ConvertNumberToString(value) + "D";
case JsonFormatStrings.Float:
return ConvertNumberToString(value) + "F";
case JsonFormatStrings.Decimal:
return ConvertNumberToString(value) + "M";
default:
return type.IsInteger() ?
ConvertNumberToString(value) :
ConvertNumberToString(value) + "D";
}

return null;
}

/// <summary>Gets the enum default value.</summary>
Expand All @@ -121,7 +116,7 @@ public override string GetNumericValue(JsonObjectType type, object value, string
/// <param name="typeNameHint">The type name hint.</param>
/// <param name="typeResolver">The type resolver.</param>
/// <returns>The enum default value.</returns>
protected override string GetEnumDefaultValue(JsonSchema schema, JsonSchema actualSchema, string typeNameHint, TypeResolverBase typeResolver)
protected override string GetEnumDefaultValue(JsonSchema schema, JsonSchema actualSchema, string? typeNameHint, TypeResolverBase typeResolver)
{
return _settings.Namespace + "." + base.GetEnumDefaultValue(schema, actualSchema, typeNameHint, typeResolver);
}
Expand Down
Loading

0 comments on commit 85fdd00

Please sign in to comment.