Skip to content

Commit

Permalink
Fix #399
Browse files Browse the repository at this point in the history
- Generate implicit operator string if requested
- Eliminate some unused methods in code generation
- Fix bug: dependent property collection is never adding dependent properties
- Update package versions
  • Loading branch information
mwadams committed Aug 26, 2024
1 parent c7cb962 commit 38e62c4
Show file tree
Hide file tree
Showing 48 changed files with 531 additions and 357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.VisualStudio.DiagnosticsHub.BenchmarkDotNetDiagnosers" Version="17.12.35209.2" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JsonSchema.Net" Version="7.1.2" />
<PackageReference Include="JsonSchema.Net" Version="7.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="JsonPatch.Net" Version="3.1.1" />
</ItemGroup>
Expand Down
103 changes: 58 additions & 45 deletions Solutions/Corvus.Json.Benchmarking/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
"net8.0": {
"BenchmarkDotNet": {
"type": "Direct",
"requested": "[0.13.12, )",
"resolved": "0.13.12",
"contentHash": "aKnzpUZJJfLBHG7zcfQZhCexZQKcJgElC8qcFUTXPMYFlVauJBobuOmtRnmrapqC2j7EjjZCsPxa3yLvFLx5/Q==",
"requested": "[0.14.0, )",
"resolved": "0.14.0",
"contentHash": "eIPSDKi3oni734M1rt/XJAwGQQOIf9gLjRRKKJ0HuVy3vYd7gnmAIX1bTjzI9ZbAY/nPddgqqgM/TeBYitMCIg==",
"dependencies": {
"BenchmarkDotNet.Annotations": "0.13.12",
"BenchmarkDotNet.Annotations": "0.14.0",
"CommandLineParser": "2.9.1",
"Gee.External.Capstone": "2.3.0",
"Iced": "1.17.0",
"Microsoft.CodeAnalysis.CSharp": "4.1.0",
"Microsoft.Diagnostics.Runtime": "2.2.332302",
"Microsoft.Diagnostics.Tracing.TraceEvent": "3.0.2",
"Microsoft.Diagnostics.Tracing.TraceEvent": "3.1.8",
"Microsoft.DotNet.PlatformAbstractions": "3.1.6",
"Perfolizer": "[0.2.1]",
"Perfolizer": "[0.3.17]",
"System.Management": "5.0.0"
}
},
"BenchmarkDotNet.Diagnostics.Windows": {
"type": "Direct",
"requested": "[0.13.12, )",
"resolved": "0.13.12",
"contentHash": "HdARbwcGFymgrSFoLVtuJaacyNW9WLuGljX0hsTarSO+80nI2OmbDS09R+I9kIeJ8Gn/1zJFjKgefmAlADhlww==",
"requested": "[0.14.0, )",
"resolved": "0.14.0",
"contentHash": "9jK9Gy7ODqHEJk/lWiSdYcyAnQ5LLPyWojWw5keFmKV6lgeqWZwQz7Z2eJNFd0a2OA0CfonnF9Wb2f9uqYfg3Q==",
"dependencies": {
"BenchmarkDotNet": "0.13.12",
"Microsoft.Diagnostics.Tracing.TraceEvent": "3.0.2"
"BenchmarkDotNet": "0.14.0",
"Microsoft.Diagnostics.Tracing.TraceEvent": "3.1.8"
}
},
"Endjin.RecommendedPractices.GitHub": {
"type": "Direct",
"requested": "[2.1.12, )",
"resolved": "2.1.12",
"contentHash": "JEOlUQymdvrI6OeVHPTpakLhOJvkLdvmH+wJNNdjqSq3FtZ2LnqKei+4AMFUzTdJcL6RF3KGD3x0AqUfhYgWcw==",
"requested": "[2.1.13, )",
"resolved": "2.1.13",
"contentHash": "ZefZtlE4NE4ajKMzUtdeb9+SSWv95gutAykQmTEuj2Ln13/1etgxha9QFhrALHr+ewvUH7M3X1qh9HBmWMLRFg==",
"dependencies": {
"Endjin.RecommendedPractices": "2.1.12",
"Endjin.RecommendedPractices": "2.1.13",
"Microsoft.SourceLink.GitHub": "1.1.1"
}
},
Expand All @@ -51,9 +51,9 @@
},
"JsonSchema.Net": {
"type": "Direct",
"requested": "[7.1.2, )",
"resolved": "7.1.2",
"contentHash": "tvM82Wpsyk+C5aUWkqPZLo2ANDjEfCoDa9R24k7jRkCrwxbXnSBb7NpU1pz0ufp6qw+jIekHD9xJdUkjUtnZxQ==",
"requested": "[7.2.2, )",
"resolved": "7.2.2",
"contentHash": "vDmn5svfDsgXc2bz9LWiTQoCaxb2VPG1XviL0CenohogBIMGuUH9XMGIZE6hA8IK8d6wru0nUlGX+5jpIgCFiQ==",
"dependencies": {
"JsonPointer.Net": "5.0.0"
}
Expand All @@ -77,6 +77,21 @@
"resolved": "17.12.35209.2",
"contentHash": "4zjVbCbmOwgY56TO9MZX5o2Amy3uwL4iBqktg0ouWlxt90BRoUh7X50nq6ypKsbf0QSzK1lV5Tm/hwa06Z3AqA=="
},
"Roslynator.Analyzers": {
"type": "Direct",
"requested": "[4.12.4, )",
"resolved": "4.12.4",
"contentHash": "isl8hAh7yFNjyBEC4YlTSi+xGBblqBUC/2MCMmnBPwuXPewb7XYnMRzT3vXbP/gOGwT8hZUOy1g/aRH3lAF/NQ=="
},
"StyleCop.Analyzers": {
"type": "Direct",
"requested": "[1.2.0-beta.556, )",
"resolved": "1.2.0-beta.556",
"contentHash": "llRPgmA1fhC0I0QyFLEcjvtM2239QzKr/tcnbsjArLMJxJlu0AA5G7Fft0OI30pHF3MW63Gf4aSSsjc5m82J1Q==",
"dependencies": {
"StyleCop.Analyzers.Unstable": "1.2.0.556"
}
},
"System.Private.Uri": {
"type": "Direct",
"requested": "[4.3.2, )",
Expand Down Expand Up @@ -107,8 +122,8 @@
},
"BenchmarkDotNet.Annotations": {
"type": "Transitive",
"resolved": "0.13.12",
"contentHash": "4zmFOOJqW1GrEP/t5XKgh97LH9r6zixGy2IA0JAaoTNNnZ8kPBt9u/XagsGNyV0e7rglOpFcWc6wI5EjefKpKA=="
"resolved": "0.14.0",
"contentHash": "CUDCg6bgHrDzhjnA+IOBl5gAo8Y5hZ2YSs7MBXrYMlMKpBZqrD5ez0537uDveOkcf+YWAoK+S4sMcuWPbIz8bw=="
},
"CommandLineParser": {
"type": "Transitive",
Expand All @@ -133,8 +148,8 @@
},
"Endjin.RecommendedPractices": {
"type": "Transitive",
"resolved": "2.1.12",
"contentHash": "OZObdtlvF6isizGzO0Vydwmj2IR8GxydcTMGCoA9lmejnlCRWYPuyJXr3ULknlJ23hHDkyLFnu/xNA4duMr2SQ==",
"resolved": "2.1.13",
"contentHash": "ZXMVKFaBJYaAfRKS/Uv8kUANDsEj2L9H5L4XVXyZULI0UANqZ/ROVTpOqulkukf3UFc/jnnVG2EfByynTiztDg==",
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1"
}
Expand Down Expand Up @@ -185,8 +200,8 @@
},
"Microsoft.CodeAnalysis.Common": {
"type": "Transitive",
"resolved": "4.10.0",
"contentHash": "7O4+dn0fNKykPpEB1i8/5EKzwD3fuu/shdbbnnsBmdiHMaBz6telOubDFwPwLQQ/PvOAWTFIWWTyAOmWvXRD2g==",
"resolved": "4.11.0",
"contentHash": "djf8ujmqYImFgB04UGtcsEhHrzVqzHowS+EEl/Yunc5LdrYrZhGBWUTXoCF0NzYXJxtfuD+UVQarWpvrNc94Qg==",
"dependencies": {
"Microsoft.CodeAnalysis.Analyzers": "3.3.4",
"System.Collections.Immutable": "8.0.0",
Expand All @@ -195,11 +210,11 @@
},
"Microsoft.CodeAnalysis.CSharp": {
"type": "Transitive",
"resolved": "4.10.0",
"contentHash": "iifqKy3KvCgPABHFbFlSxjEoE+OItZGuZ191NM/TWV750m1jMypr7BtrP65ET+OK2KNVupO8S8xCtxbNqw056A==",
"resolved": "4.11.0",
"contentHash": "6XYi2EusI8JT4y2l/F3VVVS+ISoIX9nqHsZRaG6W5aFeJ5BEuBosHfT/ABb73FN0RZ1Z3cj2j7cL28SToJPXOw==",
"dependencies": {
"Microsoft.CodeAnalysis.Analyzers": "3.3.4",
"Microsoft.CodeAnalysis.Common": "[4.10.0]",
"Microsoft.CodeAnalysis.Common": "[4.11.0]",
"System.Collections.Immutable": "8.0.0",
"System.Reflection.Metadata": "8.0.0"
}
Expand All @@ -225,10 +240,11 @@
},
"Microsoft.Diagnostics.Tracing.TraceEvent": {
"type": "Transitive",
"resolved": "3.0.2",
"contentHash": "Pr7t+Z/qBe6DxCow4BmYmDycHe2MrGESaflWXRcSUI4XNGyznx1ttS+9JNOxLuBZSoBSPTKw9Dyheo01Yi6anQ==",
"resolved": "3.1.8",
"contentHash": "kl3UMrZKSeSEYZ8rt/GjLUQToREjgQABqfg6PzQBmSlYHTZOKE9ePEOS2xptROQ9SVvngg3QGX51TIT11iZ0wA==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "4.5.3"
"Microsoft.Win32.Registry": "4.4.0",
"System.Runtime.CompilerServices.Unsafe": "5.0.0"
}
},
"Microsoft.DotNet.PlatformAbstractions": {
Expand Down Expand Up @@ -371,8 +387,8 @@
},
"Microsoft.Extensions.ObjectPool": {
"type": "Transitive",
"resolved": "8.0.7",
"contentHash": "2yLweyqmpuuFSRo+I3sLHMxmnAgNcI537kBJiyv49U2ZEqo00jZcG8lrnD8uCiOJp9IklYyTZULtbsXoFVzsjQ=="
"resolved": "8.0.8",
"contentHash": "wnjTFjEvvSbOs3iMfl6CeJcUgPHZMYUB9uAQbGQGxGwVRl4GydNpMSkVntTzoi7AqQeYumU9yDSNeVbpq+ebow=="
},
"Microsoft.Extensions.Options": {
"type": "Transitive",
Expand Down Expand Up @@ -443,11 +459,13 @@
},
"Perfolizer": {
"type": "Transitive",
"resolved": "0.2.1",
"contentHash": "Dt4aCxCT8NPtWBKA8k+FsN/RezOQ2C6omNGm5o/qmYRiIwlQYF93UgFmeF1ezVNsztTnkg7P5P63AE+uNkLfrw==",
"dependencies": {
"System.Memory": "4.5.3"
}
"resolved": "0.3.17",
"contentHash": "FQgtCoF2HFwvzKWulAwBS5BGLlh8pgbrJtOp47jyBwh2CW16juVtacN1azOA2BqdrJXkXTNLNRMo7ZlHHiuAnA=="
},
"StyleCop.Analyzers.Unstable": {
"type": "Transitive",
"resolved": "1.2.0.556",
"contentHash": "zvn9Mqs/ox/83cpYPignI8hJEM2A93s2HkHs8HYMOAQW0PkampyoErAiIyKxgTLqbbad29HX/shv/6LGSjPJNQ=="
},
"System.Buffers": {
"type": "Transitive",
Expand Down Expand Up @@ -491,11 +509,6 @@
"System.CodeDom": "5.0.0"
}
},
"System.Memory": {
"type": "Transitive",
"resolved": "4.5.3",
"contentHash": "3oDzvc/zzetpTKWMShs1AADwZjQ/36HnsufHRPcOjyRAAMLDlu2iD33MBI2opxnezcVUtXyqDXXjoFMOU9c7SA=="
},
"System.Reflection": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -650,7 +663,7 @@
"dependencies": {
"CommunityToolkit.HighPerformance": "[8.2.2, )",
"Corvus.Json.CodeGeneration": "[1.0.0, )",
"Microsoft.CodeAnalysis.CSharp": "[4.10.0, )",
"Microsoft.CodeAnalysis.CSharp": "[4.11.0, )",
"System.CodeDom": "[8.0.0, )"
}
},
Expand All @@ -668,7 +681,7 @@
"CommunityToolkit.HighPerformance": "[8.2.2, )",
"Corvus.UriTemplates": "[2.0.0, )",
"Microsoft.Extensions.Http": "[8.0.0, )",
"Microsoft.Extensions.ObjectPool": "[8.0.7, )",
"Microsoft.Extensions.ObjectPool": "[8.0.8, )",
"NodaTime": "[3.1.11, )",
"System.Text.Json": "[8.0.4, )"
}
Expand All @@ -687,7 +700,7 @@
"Corvus.Json.CodeGeneration.CorvusVocabulary": "[1.0.0, )",
"Corvus.Json.CodeGeneration.OpenApi30": "[1.0.0, )",
"Corvus.Json.ExtendedTypes": "[1.0.0, )",
"Microsoft.CodeAnalysis.CSharp": "[4.10.0, )",
"Microsoft.CodeAnalysis.CSharp": "[4.11.0, )",
"Microsoft.Extensions.DependencyModel": "[8.0.1, )",
"System.CodeDom": "[8.0.0, )",
"System.Runtime.Loader": "[4.3.0, )"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.12">
<PackageReference Include="Endjin.RecommendedPractices.GitHub" Version="2.1.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="System.CodeDom" Version="8.0.0" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ public IReadOnlyCollection<GeneratedCodeFile> GenerateCodeFor(IEnumerable<TypeDe
namesSeen[typeDeclaration.FullyQualifiedDotnetTypeName()] = typeDeclaration;
}
#endif
typeDeclaration.SetCSharpOptions(this.options);

if (generator.TryBeginTypeDeclaration(typeDeclaration))
{
foreach (ICodeFileBuilder codeFileBuilder in this.codeFileBuilderRegistry.RegisteredBuilders)
Expand Down Expand Up @@ -205,6 +203,8 @@ public void IdentifyNonGeneratedType(TypeDeclaration typeDeclaration, Cancellati
return;
}

typeDeclaration.SetCSharpOptions(this.options);

JsonReferenceBuilder reference = GetReferenceWithoutQuery(typeDeclaration);

Span<char> typeNameBuffer = stackalloc char[Formatting.MaxIdentifierLength];
Expand Down Expand Up @@ -592,6 +592,7 @@ public readonly struct Namespace(JsonReference baseUri, string dotnetNamespace)
/// <param name="optionalAsNullable">If true, then generate nullable types for optional parameters.</param>
/// <param name="disabledNamingHeuristics">The list of well-known names of naming heuristics to disable.</param>
/// <param name="fileExtension">Gets the file extension to use. Defaults to <c>.cs</c>.</param>
/// <param name="useImplicitOperatorString">If true, then the string conversion will be implicit.</param>
public class Options(
string defaultNamespace,
NamedType[]? namedTypes = null,
Expand All @@ -600,7 +601,8 @@ public class Options(
bool alwaysAssertFormat = true,
bool optionalAsNullable = false,
string[]? disabledNamingHeuristics = null,
string fileExtension = ".cs")
string fileExtension = ".cs",
bool useImplicitOperatorString = false)
{
private readonly FrozenDictionary<string, NamedType> namedTypeMap = namedTypes?.ToFrozenDictionary(kvp => kvp.Reference, kvp => kvp) ?? FrozenDictionary<string, NamedType>.Empty;
private readonly FrozenDictionary<string, string> namespaceMap = namespaces?.ToFrozenDictionary(kvp => kvp.BaseUri, kvp => kvp.DotnetNamespace) ?? FrozenDictionary<string, string>.Empty;
Expand Down Expand Up @@ -635,6 +637,11 @@ public class Options(
/// </summary>
internal string FileExtension { get; } = fileExtension;

/// <summary>
/// Gets a value indicating whether to generate an implict operator for conversion to <see langword="string"/>.
/// </summary>
internal bool UseImplicitOperatorString { get; } = useImplicitOperatorString;

/// <summary>
/// Gets the array of disabled naming heuristics.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static CodeGenerator AppendExplicitConversionToString(
/// <param name="value">The value from which to convert.</param>
/// <exception cref="InvalidOperationException">The value was not a string.</exception>
""")
.AppendIndent("public static explicit operator string(")
.AppendIndent("public static ", typeDeclaration.UseImplicitOperatorString() ? "implicit" : "explicit", " operator string(")
.Append(typeDeclaration.DotnetTypeName())
.AppendLine(" value)")
.AppendBlockIndent(
Expand Down
Loading

0 comments on commit 38e62c4

Please sign in to comment.