Skip to content

Commit

Permalink
Move location of attribute in nested types (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Dec 4, 2023
1 parent abc8c7b commit a274ba0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
12 changes: 1 addition & 11 deletions src/StronglyTypedIds/SourceGenerationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ internal static class SourceGenerationHelper
}

var hasGenericParent = false;
if (addGeneratedCodeAttribute && parentClass is not null)
{
addGeneratedCodeAttribute = false;
AddGeneratedCodeAttribute(sb);
}

while (parentClass is { } parent)
{
Expand Down Expand Up @@ -85,7 +80,7 @@ internal static class SourceGenerationHelper

if (addGeneratedCodeAttribute)
{
AddGeneratedCodeAttribute(sb);
sb.AppendLine($""" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "{Constants.StronglyTypedIdsVersion}")]""");
}

sb.AppendLine(template);
Expand All @@ -103,11 +98,6 @@ internal static class SourceGenerationHelper
}

return sb.ToString();

static void AddGeneratedCodeAttribute(StringBuilder sb)
{
sb.AppendLine($""" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "{Constants.StronglyTypedIdsVersion}")]""");
}
}

internal static string CreateSourceName(StringBuilder sb, string nameSpace, ParentClass? parent, string name, string template)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#nullable enable
namespace SomeNamespace
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
public partial class ParentClass<T> where T: new()
{
internal partial record InnerClass<TKey, TValue>
{
public partial struct InnerStruct
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
partial struct MyId :
#if NET6_0_OR_GREATER
global::System.ISpanFormattable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#nullable enable
namespace SomeNamespace
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
public partial class ParentClass
{
[global::System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))]
[global::System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
partial struct MyId :
#if NET6_0_OR_GREATER
global::System.ISpanFormattable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#nullable enable
namespace SomeNamespace
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
public partial class ParentClass
{
internal partial record InnerClass
Expand All @@ -21,6 +20,7 @@ namespace SomeNamespace
{
[global::System.ComponentModel.TypeConverter(typeof(MyIdTypeConverter))]
[global::System.Text.Json.Serialization.JsonConverter(typeof(MyIdSystemTextJsonConverter))]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("StronglyTypedId", "1.0.0-beta6")]
partial struct MyId :
#if NET6_0_OR_GREATER
global::System.ISpanFormattable,
Expand Down

0 comments on commit a274ba0

Please sign in to comment.