From 10532fc4ff9c9d8cf881c3651084c0d0e6c13d21 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Jul 2024 18:23:53 +0100 Subject: [PATCH] Use KiotaVersion.Current() Use `KiotaVersion.Current()` instead of reflection to render the version for `[GeneratedCode]` to address feedback. --- src/Kiota.Builder/Writers/CSharp/CodeClassDeclarationWriter.cs | 2 +- src/Kiota.Builder/Writers/CSharp/CodeEnumWriter.cs | 2 +- .../Writers/CSharp/CodeClassDeclarationWriterTests.cs | 2 +- tests/Kiota.Builder.Tests/Writers/CSharp/CodeEnumWriterTests.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Writers/CSharp/CodeClassDeclarationWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeClassDeclarationWriter.cs index 411cb9c9f9..e02a5a5f52 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeClassDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeClassDeclarationWriter.cs @@ -7,7 +7,7 @@ namespace Kiota.Builder.Writers.CSharp; public class CodeClassDeclarationWriter : BaseElementWriter { public static string AutoGenerationHeader => "// "; - public static string GeneratedCodeAttribute { get; } = $"[global::System.CodeDom.Compiler.GeneratedCode(\"Kiota\", \"{typeof(CodeClassDeclarationWriter).Assembly.GetName().Version}\")]"; + public static string GeneratedCodeAttribute { get; } = $"[global::System.CodeDom.Compiler.GeneratedCode(\"Kiota\", \"{Kiota.Generated.KiotaVersion.Current()}\")]"; public CodeClassDeclarationWriter(CSharpConventionService conventionService) : base(conventionService) { } public override void WriteCodeElement(ClassDeclaration codeElement, LanguageWriter writer) { diff --git a/src/Kiota.Builder/Writers/CSharp/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeEnumWriter.cs index e4ba9d61d5..467299f8a3 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeEnumWriter.cs @@ -9,7 +9,7 @@ namespace Kiota.Builder.Writers.CSharp; public class CodeEnumWriter : BaseElementWriter { public static string AutoGenerationHeader => "// "; - public static string GeneratedCodeAttribute { get; } = $"[global::System.CodeDom.Compiler.GeneratedCode(\"Kiota\", \"{typeof(CodeClassDeclarationWriter).Assembly.GetName().Version}\")]"; + public static string GeneratedCodeAttribute { get; } = $"[global::System.CodeDom.Compiler.GeneratedCode(\"Kiota\", \"{Kiota.Generated.KiotaVersion.Current()}\")]"; public CodeEnumWriter(CSharpConventionService conventionService) : base(conventionService) { } public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter writer) { diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeClassDeclarationWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeClassDeclarationWriterTests.cs index 8243e6a0a3..dcb3867f5d 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeClassDeclarationWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeClassDeclarationWriterTests.cs @@ -113,7 +113,7 @@ public void WritesGeneratedCodeAttribute() { codeElementWriter.WriteCodeElement(parentClass.StartBlock, writer); var result = tw.ToString(); - var pattern = @"\s+\[global::System\.CodeDom\.Compiler\.GeneratedCode\(""Kiota"", ""[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+""\)\]"; + var pattern = @"\s+\[global::System\.CodeDom\.Compiler\.GeneratedCode\(""Kiota"", ""[0-9]+\.[0-9]+\.[0-9]+\""\)\]"; Assert.Matches(pattern, result); } } diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeEnumWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeEnumWriterTests.cs index cd7d0e1176..3cba9639ce 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeEnumWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeEnumWriterTests.cs @@ -136,7 +136,7 @@ public void WritesGeneratedCodeAttribute() currentEnum.AddOption(new CodeEnumOption { Name = "option2" }); writer.Write(currentEnum); var result = tw.ToString(); - var pattern = @"\s+\[global::System\.CodeDom\.Compiler\.GeneratedCode\(""Kiota"", ""[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+""\)\]"; + var pattern = @"\s+\[global::System\.CodeDom\.Compiler\.GeneratedCode\(""Kiota"", ""[0-9]+\.[0-9]+\.[0-9]+\""\)\]"; Assert.Matches(pattern, result); } }