From 401451a8c7bd6fd8cc9a4648c4c69be5b688a11d Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:03:25 -0700 Subject: [PATCH 01/12] [CF] custom interface functionality is working, now to write tests --- .../AutomaticInterfaceGenerator.cs | 4 +- .../AutomaticInterface/Builder.cs | 35 ++++++----------- .../GeneratedSymbolDetails.cs | 39 +++++++++++++++++++ .../RegisterAttributesExtensions.cs | 4 +- .../DemoClassWithCustomInterfaceName.cs | 12 ++++++ 5 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs create mode 100644 AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs diff --git a/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs b/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs index e9a076a..a1e14f3 100644 --- a/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs +++ b/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs @@ -10,6 +10,8 @@ public class AutomaticInterfaceGenerator : IIncrementalGenerator { public const string DefaultAttributeName = "GenerateAutomaticInterface"; public const string IgnoreAutomaticInterfaceAttributeName = "IgnoreAutomaticInterface"; + public const string NamespaceParameterName = "namespaceName"; + public const string InterfaceParameterName = "interfaceName"; public void Initialize(IncrementalGeneratorInitializationContext context) { @@ -49,4 +51,4 @@ ImmutableArray enumerations context.AddSource(hintName, code); } } -} +} \ No newline at end of file diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 1f028e9..9718032 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -16,16 +16,16 @@ private static string InheritDoc(ISymbol source) => new( genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, memberOptions: SymbolDisplayMemberOptions.IncludeParameters - | SymbolDisplayMemberOptions.IncludeContainingType, + | SymbolDisplayMemberOptions.IncludeContainingType, parameterOptions: SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeDefaultValue - | SymbolDisplayParameterOptions.IncludeName, + | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeDefaultValue + | SymbolDisplayParameterOptions.IncludeName, typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier - | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers ); /// @@ -35,7 +35,7 @@ private static string InheritDoc(ISymbol source) => new( genericsOptions: FullyQualifiedDisplayFormat.GenericsOptions, memberOptions: FullyQualifiedDisplayFormat.MemberOptions - & ~SymbolDisplayMemberOptions.IncludeContainingType, + & ~SymbolDisplayMemberOptions.IncludeContainingType, parameterOptions: FullyQualifiedDisplayFormat.ParameterOptions, typeQualificationStyle: FullyQualifiedDisplayFormat.TypeQualificationStyle, globalNamespaceStyle: FullyQualifiedDisplayFormat.GlobalNamespaceStyle, @@ -52,11 +52,9 @@ is not ClassDeclarationSyntax classSyntax { return string.Empty; } - var namespaceName = GetNameSpace(typeSymbol); - var interfaceName = $"I{classSyntax.GetClassName()}"; - - var interfaceGenerator = new InterfaceBuilder(namespaceName, interfaceName); + var symbolDetails = GetSymbolDetails(typeSymbol, classSyntax); + var interfaceGenerator = new InterfaceBuilder(symbolDetails.NamespaceName, symbolDetails.InterfaceName); interfaceGenerator.AddClassDocumentation(GetDocumentationForClass(classSyntax)); interfaceGenerator.AddGeneric(GetGeneric(classSyntax, namedTypeSymbol)); @@ -77,7 +75,7 @@ is not ClassDeclarationSyntax classSyntax return generatedCode; } - private static string GetNameSpace(ISymbol typeSymbol) + private static GeneratedSymbolDetails GetSymbolDetails(ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) { var generationAttribute = typeSymbol .GetAttributes() @@ -86,16 +84,7 @@ private static string GetNameSpace(ISymbol typeSymbol) && x.AttributeClass.Name.Contains(AutomaticInterfaceGenerator.DefaultAttributeName) ); - if (generationAttribute == null) - { - return typeSymbol.ContainingNamespace.ToDisplayString(); - } - - var customNs = generationAttribute.ConstructorArguments.FirstOrDefault().Value?.ToString(); - - return string.IsNullOrWhiteSpace(customNs) - ? typeSymbol.ContainingNamespace.ToDisplayString() - : customNs!; + return new GeneratedSymbolDetails(generationAttribute, typeSymbol, classSyntax); } private static void AddMethodsToInterface(List members, InterfaceBuilder codeGenerator) @@ -308,4 +297,4 @@ private static string GetGeneric(TypeDeclarationSyntax classSyntax, INamedTypeSy return $"{classSyntax.TypeParameterList?.ToFullString().Trim()} {string.Join(" ", whereStatements)}".Trim(); } -} +} \ No newline at end of file diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs new file mode 100644 index 0000000..f1ca01c --- /dev/null +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -0,0 +1,39 @@ +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace AutomaticInterface; + +internal sealed class GeneratedSymbolDetails(AttributeData? generationAttribute, ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) +{ + /// + /// Represents the namespace name associated with the generated interface or type symbol. + /// This value is typically derived from the provided generation attribute or defaults + /// to the containing namespace of the type symbol. + /// + public string NamespaceName { get; } = PrepareValue(generationAttribute, AutomaticInterfaceGenerator.NamespaceParameterName, typeSymbol.ContainingNamespace.ToDisplayString()); + + /// + /// Represents the name of the interface generated for a class. The interface name + /// is derived from the class name, prefixed with 'I', unless overridden by a specific + /// attribute value during generation. + /// + public string InterfaceName { get; } = PrepareValue(generationAttribute, AutomaticInterfaceGenerator.InterfaceParameterName, $"I{classSyntax.GetClassName()}"); + + private static string PrepareValue(AttributeData? generationAttribute, string key, string defaultValue) + { + var parameterSymbol = generationAttribute?.AttributeConstructor?.Parameters.SingleOrDefault(x => x.Name == key); + + if (parameterSymbol != null) + { + var index = generationAttribute!.AttributeConstructor!.Parameters.IndexOf(parameterSymbol); + var result = generationAttribute.ConstructorArguments[index].Value!.ToString(); + if (!string.IsNullOrWhiteSpace(result)) + { + return result; + } + } + + return defaultValue; + } +} \ No newline at end of file diff --git a/AutomaticInterface/AutomaticInterface/RegisterAttributesExtensions.cs b/AutomaticInterface/AutomaticInterface/RegisterAttributesExtensions.cs index d18d044..a21d7e1 100644 --- a/AutomaticInterface/AutomaticInterface/RegisterAttributesExtensions.cs +++ b/AutomaticInterface/AutomaticInterface/RegisterAttributesExtensions.cs @@ -24,10 +24,12 @@ namespace AutomaticInterface /// /// Use source generator to automatically create a Interface from this class /// + /// Namespace name for the generated interface. Defaults to the same namespace as the class. + /// Interface name for the generated interface. Defaults to an interface version of the class name. [AttributeUsage(AttributeTargets.Class)] internal sealed class {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute : Attribute { - internal {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute(string namespaceName = "") { } + internal {{{AutomaticInterfaceGenerator.DefaultAttributeName}}}Attribute(string {{{AutomaticInterfaceGenerator.NamespaceParameterName}}} = "", string {{{AutomaticInterfaceGenerator.InterfaceParameterName}}} = "") { } } } """, diff --git a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs new file mode 100644 index 0000000..2ed0d49 --- /dev/null +++ b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs @@ -0,0 +1,12 @@ +using AutomaticInterface; + +namespace AutomaticInterfaceExample; + +[GenerateAutomaticInterface(interfaceName: "ISpecialInterface")] +public class DemoClassWithCustomInterfaceName : ISpecialInterface +{ + /// + /// This is a test method + /// + public void Test() { } +} \ No newline at end of file From bfb551cc0fff3763e556f16b92a5d6f6b38749a0 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:22:06 -0700 Subject: [PATCH 02/12] [CF] Adds tests for custom interface names --- .../Misc/Misc.CustomInterface.verified.txt | 18 + ...c.CustomInterfaceAndNamespace.verified.txt | 18 + ...ndNamespaceParametersReversed.verified.txt | 18 + AutomaticInterface/Tests/Misc/Misc.cs | 438 ++++++++++-------- AutomaticInterface/Tests/Tests.csproj | 6 - 5 files changed, 309 insertions(+), 189 deletions(-) create mode 100644 AutomaticInterface/Tests/Misc/Misc.CustomInterface.verified.txt create mode 100644 AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespace.verified.txt create mode 100644 AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespaceParametersReversed.verified.txt diff --git a/AutomaticInterface/Tests/Misc/Misc.CustomInterface.verified.txt b/AutomaticInterface/Tests/Misc/Misc.CustomInterface.verified.txt new file mode 100644 index 0000000..60c018a --- /dev/null +++ b/AutomaticInterface/Tests/Misc/Misc.CustomInterface.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace AutomaticInterfaceExample +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface ISpecialInterface + { + /// + void Test(); + + } +} diff --git a/AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespace.verified.txt b/AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespace.verified.txt new file mode 100644 index 0000000..f7ef5ba --- /dev/null +++ b/AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespace.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace CustomNamespace +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface ISpecialInterface + { + /// + void Test(); + + } +} diff --git a/AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespaceParametersReversed.verified.txt b/AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespaceParametersReversed.verified.txt new file mode 100644 index 0000000..f7ef5ba --- /dev/null +++ b/AutomaticInterface/Tests/Misc/Misc.CustomInterfaceAndNamespaceParametersReversed.verified.txt @@ -0,0 +1,18 @@ +//-------------------------------------------------------------------------------------------------- +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. +// +//-------------------------------------------------------------------------------------------------- + +namespace CustomNamespace +{ + [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] + public partial interface ISpecialInterface + { + /// + void Test(); + + } +} diff --git a/AutomaticInterface/Tests/Misc/Misc.cs b/AutomaticInterface/Tests/Misc/Misc.cs index c573a0b..8dde41b 100644 --- a/AutomaticInterface/Tests/Misc/Misc.cs +++ b/AutomaticInterface/Tests/Misc/Misc.cs @@ -7,26 +7,26 @@ public async Task WorksWithOptionalStructParameters() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample; + namespace AutomaticInterfaceExample; - public struct MyStruct - { - private int Bar; - } + public struct MyStruct + { + private int Bar; + } - [GenerateAutomaticInterface] - public class DemoClass - { - public bool TryStartTransaction(MyStruct data = default(MyStruct)) - { - return true; - } - } + [GenerateAutomaticInterface] + public class DemoClass + { + public bool TryStartTransaction(MyStruct data = default(MyStruct)) + { + return true; + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -35,17 +35,17 @@ public async Task GeneratesEmptyInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - [GenerateAutomaticInterface] - class DemoClass - { - } - } + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface] + class DemoClass + { + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -55,21 +55,21 @@ public async Task CopiesDocumentationOfClassToInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - public string Hello { get; private set; } - } - } + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + public string Hello { get; private set; } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -79,26 +79,26 @@ public async Task DoesNotCopyCtorToToInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - DemoClass(string x) - { + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + DemoClass(string x) + { - } + } - public string Hello { get; private set; } - } - } + public string Hello { get; private set; } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -108,26 +108,26 @@ public async Task DoesNotCopyStaticMethodsToInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - public static string Hello => "abc"; // property + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + public static string Hello => "abc"; // property - public static string StaticMethod() // method - { - return "static"; - } - } - } + public static string StaticMethod() // method + { + return "static"; + } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -137,32 +137,32 @@ public async Task DoesNotCopyIndexerToInterface() { const string code = """ - using AutomaticInterface; - using System; - - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - - private int[] arr = new int[100]; - - /// - /// Bla bla - /// - public int this[int index] // currently ignored - { - get => arr[index]; - set => arr[index] = value; - } - } - } - - """; + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + + private int[] arr = new int[100]; + + /// + /// Bla bla + /// + public int this[int index] // currently ignored + { + get => arr[index]; + set => arr[index] = value; + } + } + } + + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -172,63 +172,63 @@ public async Task FullExample() { const string code = """ - using AutomaticInterface; - using System; + using AutomaticInterface; + using System; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - /// - /// Property Documentation will be copied - /// - public string Hello { get; set; } // included, get and set are copied to the interface when public + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + /// + /// Property Documentation will be copied + /// + public string Hello { get; set; } // included, get and set are copied to the interface when public - public string OnlyGet { get; } // included, get and set are copied to the interface when public + public string OnlyGet { get; } // included, get and set are copied to the interface when public - /// - /// Method Documentation will be copied - /// - public string AMethod(string x, string y) // included - { - return BMethod(x,y); - } + /// + /// Method Documentation will be copied + /// + public string AMethod(string x, string y) // included + { + return BMethod(x,y); + } - private string BMethod(string x, string y) // ignored because not public - { - return x + y; - } + private string BMethod(string x, string y) // ignored because not public + { + return x + y; + } - public static string StaticProperty => "abc"; // static property, ignored + public static string StaticProperty => "abc"; // static property, ignored - public static string StaticMethod() // static method, ignored - { - return "static" + DateTime.Now; - } + public static string StaticMethod() // static method, ignored + { + return "static" + DateTime.Now; + } - /// - /// event Documentation will be copied - /// + /// + /// event Documentation will be copied + /// - public event EventHandler ShapeChanged; // included + public event EventHandler ShapeChanged; // included - private event EventHandler ShapeChanged2; // ignored because not public + private event EventHandler ShapeChanged2; // ignored because not public - private readonly int[] arr = new int[100]; + private readonly int[] arr = new int[100]; - public int this[int index] // currently ignored - { - get => arr[index]; - set => arr[index] = value; - } - } - } + public int this[int index] // currently ignored + { + get => arr[index]; + set => arr[index] = value; + } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -238,18 +238,90 @@ public async Task WorksWithNullableContext() { const string code = """ - using AutomaticInterface; - namespace AutomaticInterfaceExample; - [GenerateAutomaticInterface] - public class DemoClass - { - public string AMethod(DemoClass? x, string y) - { - return "Ok"; - } - } + using AutomaticInterface; + namespace AutomaticInterfaceExample; + [GenerateAutomaticInterface] + public class DemoClass + { + public string AMethod(DemoClass? x, string y) + { + return "Ok"; + } + } - """; + """; + + await Verify(Infrastructure.GenerateCode(code)); + } + + [Fact] + public async Task CustomInterfaceAndNamespace() + { + const string code = """ + + using AutomaticInterface; + + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface("CustomNamespace", "ISpecialInterface")] + public class DemoClassWithCustomInterfaceName : ISpecialInterface + { + /// + /// This is a test method + /// + public void Test() { } + } + } + + """; + + await Verify(Infrastructure.GenerateCode(code)); + } + + [Fact] + public async Task CustomInterfaceAndNamespaceParametersReversed() + { + const string code = """ + + using AutomaticInterface; + + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface(interfaceName: "ISpecialInterface", namespaceName: "CustomNamespace")] + public class DemoClassWithCustomInterfaceName : ISpecialInterface + { + /// + /// This is a test method + /// + public void Test() { } + } + } + + """; + + await Verify(Infrastructure.GenerateCode(code)); + } + + [Fact] + public async Task CustomInterface() + { + const string code = """ + + using AutomaticInterface; + + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface(interfaceName: "ISpecialInterface")] + public class DemoClassWithCustomInterfaceName : ISpecialInterface + { + /// + /// This is a test method + /// + public void Test() { } + } + } + + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -259,37 +331,37 @@ public async Task CustomNameSpace() { const string code = """ - using AutomaticInterface; - using System; - using System.IO; - using System.Threading; - using System.Threading.Tasks; - - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface("CustomNameSpace")] - class DemoClass - { - - public async Task GetFinalDocumentsByIDFails( - string agreementID, - string docType, - bool amt = false , - bool? attachSupportingDocuments = true, - CancellationToken cancellationToken = default) - { - await Task.Delay(100); - return default(Stream?); - - } - } - } - - """; + using AutomaticInterface; + using System; + using System.IO; + using System.Threading; + using System.Threading.Tasks; + + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface("CustomNameSpace")] + class DemoClass + { + + public async Task GetFinalDocumentsByIDFails( + string agreementID, + string docType, + bool amt = false , + bool? attachSupportingDocuments = true, + CancellationToken cancellationToken = default) + { + await Task.Delay(100); + return default(Stream?); + + } + } + } + + """; await Verify(Infrastructure.GenerateCode(code)); } -} +} \ No newline at end of file diff --git a/AutomaticInterface/Tests/Tests.csproj b/AutomaticInterface/Tests/Tests.csproj index 15f695b..4c9a0bf 100644 --- a/AutomaticInterface/Tests/Tests.csproj +++ b/AutomaticInterface/Tests/Tests.csproj @@ -23,10 +23,4 @@ - - - - Methods - - From 2877025e6541b70f6453f2d176e142c45e2ac9b5 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:27:11 -0700 Subject: [PATCH 03/12] [CF] build rules --- .../AutomaticInterface/AutomaticInterfaceGenerator.cs | 2 +- AutomaticInterface/AutomaticInterface/Builder.cs | 2 +- AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs | 2 +- .../DemoClassWithCustomInterfaceName.cs | 2 +- AutomaticInterface/Tests/Misc/Misc.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs b/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs index a1e14f3..aa8a5b6 100644 --- a/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs +++ b/AutomaticInterface/AutomaticInterface/AutomaticInterfaceGenerator.cs @@ -51,4 +51,4 @@ ImmutableArray enumerations context.AddSource(hintName, code); } } -} \ No newline at end of file +} diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 9718032..79786ca 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -297,4 +297,4 @@ private static string GetGeneric(TypeDeclarationSyntax classSyntax, INamedTypeSy return $"{classSyntax.TypeParameterList?.ToFullString().Trim()} {string.Join(" ", whereStatements)}".Trim(); } -} \ No newline at end of file +} diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index f1ca01c..6d48eaf 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -36,4 +36,4 @@ private static string PrepareValue(AttributeData? generationAttribute, string ke return defaultValue; } -} \ No newline at end of file +} diff --git a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs index 2ed0d49..540e695 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomInterfaceName.cs @@ -9,4 +9,4 @@ public class DemoClassWithCustomInterfaceName : ISpecialInterface /// This is a test method /// public void Test() { } -} \ No newline at end of file +} diff --git a/AutomaticInterface/Tests/Misc/Misc.cs b/AutomaticInterface/Tests/Misc/Misc.cs index 8dde41b..2695b19 100644 --- a/AutomaticInterface/Tests/Misc/Misc.cs +++ b/AutomaticInterface/Tests/Misc/Misc.cs @@ -364,4 +364,4 @@ class DemoClass await Verify(Infrastructure.GenerateCode(code)); } -} \ No newline at end of file +} From d1fbcf4e71f216b59783d68581b12358c50ea821 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:34:35 -0700 Subject: [PATCH 04/12] [CF] build rules --- .../AutomaticInterface/Builder.cs | 12 +- .../GeneratedSymbolDetails.cs | 3 +- AutomaticInterface/Tests/Misc/Misc.cs | 442 +++++++++--------- 3 files changed, 229 insertions(+), 228 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 79786ca..b0747bd 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -16,16 +16,16 @@ private static string InheritDoc(ISymbol source) => new( genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, memberOptions: SymbolDisplayMemberOptions.IncludeParameters - | SymbolDisplayMemberOptions.IncludeContainingType, + | SymbolDisplayMemberOptions.IncludeContainingType, parameterOptions: SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeDefaultValue - | SymbolDisplayParameterOptions.IncludeName, + | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeDefaultValue + | SymbolDisplayParameterOptions.IncludeName, typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier - | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers ); /// diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index 6d48eaf..5f71802 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -4,7 +4,8 @@ namespace AutomaticInterface; -internal sealed class GeneratedSymbolDetails(AttributeData? generationAttribute, ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) +internal sealed class GeneratedSymbolDetails( + AttributeData? generationAttribute, ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) { /// /// Represents the namespace name associated with the generated interface or type symbol. diff --git a/AutomaticInterface/Tests/Misc/Misc.cs b/AutomaticInterface/Tests/Misc/Misc.cs index 2695b19..06a4cfc 100644 --- a/AutomaticInterface/Tests/Misc/Misc.cs +++ b/AutomaticInterface/Tests/Misc/Misc.cs @@ -7,26 +7,26 @@ public async Task WorksWithOptionalStructParameters() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample; + namespace AutomaticInterfaceExample; - public struct MyStruct - { - private int Bar; - } + public struct MyStruct + { + private int Bar; + } - [GenerateAutomaticInterface] - public class DemoClass - { - public bool TryStartTransaction(MyStruct data = default(MyStruct)) - { - return true; - } - } + [GenerateAutomaticInterface] + public class DemoClass + { + public bool TryStartTransaction(MyStruct data = default(MyStruct)) + { + return true; + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -35,17 +35,17 @@ public async Task GeneratesEmptyInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - [GenerateAutomaticInterface] - class DemoClass - { - } - } + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface] + class DemoClass + { + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -55,21 +55,21 @@ public async Task CopiesDocumentationOfClassToInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - public string Hello { get; private set; } - } - } + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + public string Hello { get; private set; } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -79,26 +79,26 @@ public async Task DoesNotCopyCtorToToInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - DemoClass(string x) - { + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + DemoClass(string x) + { - } + } - public string Hello { get; private set; } - } - } + public string Hello { get; private set; } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -108,26 +108,26 @@ public async Task DoesNotCopyStaticMethodsToInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - public static string Hello => "abc"; // property + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + public static string Hello => "abc"; // property - public static string StaticMethod() // method - { - return "static"; - } - } - } + public static string StaticMethod() // method + { + return "static"; + } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -137,32 +137,32 @@ public async Task DoesNotCopyIndexerToInterface() { const string code = """ - using AutomaticInterface; - using System; - - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - - private int[] arr = new int[100]; - - /// - /// Bla bla - /// - public int this[int index] // currently ignored - { - get => arr[index]; - set => arr[index] = value; - } - } - } - - """; + using AutomaticInterface; + using System; + + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + + private int[] arr = new int[100]; + + /// + /// Bla bla + /// + public int this[int index] // currently ignored + { + get => arr[index]; + set => arr[index] = value; + } + } + } + + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -172,63 +172,63 @@ public async Task FullExample() { const string code = """ - using AutomaticInterface; - using System; + using AutomaticInterface; + using System; - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface] - class DemoClass - { - /// - /// Property Documentation will be copied - /// - public string Hello { get; set; } // included, get and set are copied to the interface when public + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface] + class DemoClass + { + /// + /// Property Documentation will be copied + /// + public string Hello { get; set; } // included, get and set are copied to the interface when public - public string OnlyGet { get; } // included, get and set are copied to the interface when public + public string OnlyGet { get; } // included, get and set are copied to the interface when public - /// - /// Method Documentation will be copied - /// - public string AMethod(string x, string y) // included - { - return BMethod(x,y); - } + /// + /// Method Documentation will be copied + /// + public string AMethod(string x, string y) // included + { + return BMethod(x,y); + } - private string BMethod(string x, string y) // ignored because not public - { - return x + y; - } + private string BMethod(string x, string y) // ignored because not public + { + return x + y; + } - public static string StaticProperty => "abc"; // static property, ignored + public static string StaticProperty => "abc"; // static property, ignored - public static string StaticMethod() // static method, ignored - { - return "static" + DateTime.Now; - } + public static string StaticMethod() // static method, ignored + { + return "static" + DateTime.Now; + } - /// - /// event Documentation will be copied - /// + /// + /// event Documentation will be copied + /// - public event EventHandler ShapeChanged; // included + public event EventHandler ShapeChanged; // included - private event EventHandler ShapeChanged2; // ignored because not public + private event EventHandler ShapeChanged2; // ignored because not public - private readonly int[] arr = new int[100]; + private readonly int[] arr = new int[100]; - public int this[int index] // currently ignored - { - get => arr[index]; - set => arr[index] = value; - } - } - } + public int this[int index] // currently ignored + { + get => arr[index]; + set => arr[index] = value; + } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -238,18 +238,18 @@ public async Task WorksWithNullableContext() { const string code = """ - using AutomaticInterface; - namespace AutomaticInterfaceExample; - [GenerateAutomaticInterface] - public class DemoClass - { - public string AMethod(DemoClass? x, string y) - { - return "Ok"; - } - } + using AutomaticInterface; + namespace AutomaticInterfaceExample; + [GenerateAutomaticInterface] + public class DemoClass + { + public string AMethod(DemoClass? x, string y) + { + return "Ok"; + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -259,21 +259,21 @@ public async Task CustomInterfaceAndNamespace() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - [GenerateAutomaticInterface("CustomNamespace", "ISpecialInterface")] - public class DemoClassWithCustomInterfaceName : ISpecialInterface - { - /// - /// This is a test method - /// - public void Test() { } - } - } + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface("CustomNamespace", "ISpecialInterface")] + public class DemoClassWithCustomInterfaceName : ISpecialInterface + { + /// + /// This is a test method + /// + public void Test() { } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -283,21 +283,21 @@ public async Task CustomInterfaceAndNamespaceParametersReversed() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - [GenerateAutomaticInterface(interfaceName: "ISpecialInterface", namespaceName: "CustomNamespace")] - public class DemoClassWithCustomInterfaceName : ISpecialInterface - { - /// - /// This is a test method - /// - public void Test() { } - } - } + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface(interfaceName: "ISpecialInterface", namespaceName: "CustomNamespace")] + public class DemoClassWithCustomInterfaceName : ISpecialInterface + { + /// + /// This is a test method + /// + public void Test() { } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -307,21 +307,21 @@ public async Task CustomInterface() { const string code = """ - using AutomaticInterface; + using AutomaticInterface; - namespace AutomaticInterfaceExample - { - [GenerateAutomaticInterface(interfaceName: "ISpecialInterface")] - public class DemoClassWithCustomInterfaceName : ISpecialInterface - { - /// - /// This is a test method - /// - public void Test() { } - } - } + namespace AutomaticInterfaceExample + { + [GenerateAutomaticInterface(interfaceName: "ISpecialInterface")] + public class DemoClassWithCustomInterfaceName : ISpecialInterface + { + /// + /// This is a test method + /// + public void Test() { } + } + } - """; + """; await Verify(Infrastructure.GenerateCode(code)); } @@ -331,36 +331,36 @@ public async Task CustomNameSpace() { const string code = """ - using AutomaticInterface; - using System; - using System.IO; - using System.Threading; - using System.Threading.Tasks; - - namespace AutomaticInterfaceExample - { - /// - /// Bla bla - /// - [GenerateAutomaticInterface("CustomNameSpace")] - class DemoClass - { - - public async Task GetFinalDocumentsByIDFails( - string agreementID, - string docType, - bool amt = false , - bool? attachSupportingDocuments = true, - CancellationToken cancellationToken = default) - { - await Task.Delay(100); - return default(Stream?); - - } - } - } - - """; + using AutomaticInterface; + using System; + using System.IO; + using System.Threading; + using System.Threading.Tasks; + + namespace AutomaticInterfaceExample + { + /// + /// Bla bla + /// + [GenerateAutomaticInterface("CustomNameSpace")] + class DemoClass + { + + public async Task GetFinalDocumentsByIDFails( + string agreementID, + string docType, + bool amt = false , + bool? attachSupportingDocuments = true, + CancellationToken cancellationToken = default) + { + await Task.Delay(100); + return default(Stream?); + + } + } + } + + """; await Verify(Infrastructure.GenerateCode(code)); } From cdf49fe200e577a7ff1cc2452863d5380eb91e6a Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:36:50 -0700 Subject: [PATCH 05/12] [CF] build rules --- AutomaticInterface/AutomaticInterface/Builder.cs | 2 +- .../AutomaticInterface/GeneratedSymbolDetails.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index b0747bd..3ba360b 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -35,7 +35,7 @@ private static string InheritDoc(ISymbol source) => new( genericsOptions: FullyQualifiedDisplayFormat.GenericsOptions, memberOptions: FullyQualifiedDisplayFormat.MemberOptions - & ~SymbolDisplayMemberOptions.IncludeContainingType, + & ~SymbolDisplayMemberOptions.IncludeContainingType, parameterOptions: FullyQualifiedDisplayFormat.ParameterOptions, typeQualificationStyle: FullyQualifiedDisplayFormat.TypeQualificationStyle, globalNamespaceStyle: FullyQualifiedDisplayFormat.GlobalNamespaceStyle, diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index 5f71802..d4ef600 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -5,7 +5,9 @@ namespace AutomaticInterface; internal sealed class GeneratedSymbolDetails( - AttributeData? generationAttribute, ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) + AttributeData? generationAttribute, + ITypeSymbol typeSymbol, + ClassDeclarationSyntax classSyntax) { /// /// Represents the namespace name associated with the generated interface or type symbol. From 1261462f834ce0d001f07c466ad979f0d8eb2bb1 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:40:31 -0700 Subject: [PATCH 06/12] [CF] build rules --- AutomaticInterface/AutomaticInterface/Builder.cs | 4 +++- .../AutomaticInterface/GeneratedSymbolDetails.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 3ba360b..edeb6f1 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -54,7 +54,9 @@ is not ClassDeclarationSyntax classSyntax } var symbolDetails = GetSymbolDetails(typeSymbol, classSyntax); - var interfaceGenerator = new InterfaceBuilder(symbolDetails.NamespaceName, symbolDetails.InterfaceName); + var interfaceGenerator = new InterfaceBuilder( + symbolDetails.NamespaceName, + symbolDetails.InterfaceName); interfaceGenerator.AddClassDocumentation(GetDocumentationForClass(classSyntax)); interfaceGenerator.AddGeneric(GetGeneric(classSyntax, namedTypeSymbol)); diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index d4ef600..9651562 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -5,7 +5,7 @@ namespace AutomaticInterface; internal sealed class GeneratedSymbolDetails( - AttributeData? generationAttribute, + AttributeData? generationAttribute, ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) { From b9ab08fe0791d4971c40bf9645d5fc9d9ee00424 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:42:31 -0700 Subject: [PATCH 07/12] [CF] build rules --- .../AutomaticInterface/GeneratedSymbolDetails.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index 9651562..8d62baa 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -7,7 +7,8 @@ namespace AutomaticInterface; internal sealed class GeneratedSymbolDetails( AttributeData? generationAttribute, ITypeSymbol typeSymbol, - ClassDeclarationSyntax classSyntax) + ClassDeclarationSyntax classSyntax +) { /// /// Represents the namespace name associated with the generated interface or type symbol. From f7a4f4305eab65e4a6bf1e8081fd9f43fae125c0 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:46:35 -0700 Subject: [PATCH 08/12] [CF] build rules --- AutomaticInterface/AutomaticInterface/Builder.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index edeb6f1..ea69779 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -56,7 +56,8 @@ is not ClassDeclarationSyntax classSyntax var symbolDetails = GetSymbolDetails(typeSymbol, classSyntax); var interfaceGenerator = new InterfaceBuilder( symbolDetails.NamespaceName, - symbolDetails.InterfaceName); + symbolDetails.InterfaceName + ); interfaceGenerator.AddClassDocumentation(GetDocumentationForClass(classSyntax)); interfaceGenerator.AddGeneric(GetGeneric(classSyntax, namedTypeSymbol)); From b530e442ea335db2321bc24225567f5a757ef73b Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:48:53 -0700 Subject: [PATCH 09/12] [CF] build rules --- .../AutomaticInterface/Builder.cs | 2 +- .../GeneratedSymbolDetails.cs | 13 +++++++++++-- .../Enums/Enums.WorksWithEnum.received.txt | 18 ------------------ 3 files changed, 12 insertions(+), 21 deletions(-) delete mode 100644 AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index ea69779..eb601c5 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -55,7 +55,7 @@ is not ClassDeclarationSyntax classSyntax var symbolDetails = GetSymbolDetails(typeSymbol, classSyntax); var interfaceGenerator = new InterfaceBuilder( - symbolDetails.NamespaceName, + symbolDetails.NamespaceName, symbolDetails.InterfaceName ); diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index 8d62baa..c16052b 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -15,14 +15,23 @@ ClassDeclarationSyntax classSyntax /// This value is typically derived from the provided generation attribute or defaults /// to the containing namespace of the type symbol. /// - public string NamespaceName { get; } = PrepareValue(generationAttribute, AutomaticInterfaceGenerator.NamespaceParameterName, typeSymbol.ContainingNamespace.ToDisplayString()); + public string NamespaceName { get; } = + PrepareValue( + generationAttribute, + AutomaticInterfaceGenerator.NamespaceParameterName, + typeSymbol.ContainingNamespace.ToDisplayString() + ); /// /// Represents the name of the interface generated for a class. The interface name /// is derived from the class name, prefixed with 'I', unless overridden by a specific /// attribute value during generation. /// - public string InterfaceName { get; } = PrepareValue(generationAttribute, AutomaticInterfaceGenerator.InterfaceParameterName, $"I{classSyntax.GetClassName()}"); + public string InterfaceName { get; } = + PrepareValue(generationAttribute, + AutomaticInterfaceGenerator.InterfaceParameterName, + $"I{classSyntax.GetClassName()}" + ); private static string PrepareValue(AttributeData? generationAttribute, string key, string defaultValue) { diff --git a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt b/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt deleted file mode 100644 index 90b8ad7..0000000 --- a/AutomaticInterface/Tests/Enums/Enums.WorksWithEnum.received.txt +++ /dev/null @@ -1,18 +0,0 @@ -//-------------------------------------------------------------------------------------------------- -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. -// -//-------------------------------------------------------------------------------------------------- - -namespace AutomaticInterfaceExample -{ - [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] - public partial interface IDemoClass - { - /// - void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B); - - } -} From d6907fc62464057d3a6658744f650fcf083befa7 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:50:40 -0700 Subject: [PATCH 10/12] [CF] build rules --- AutomaticInterface/AutomaticInterface/Builder.cs | 5 ++++- .../AutomaticInterface/GeneratedSymbolDetails.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index eb601c5..e329136 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -78,7 +78,10 @@ is not ClassDeclarationSyntax classSyntax return generatedCode; } - private static GeneratedSymbolDetails GetSymbolDetails(ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax) + private static GeneratedSymbolDetails GetSymbolDetails( + ITypeSymbol typeSymbol, + ClassDeclarationSyntax classSyntax + ) { var generationAttribute = typeSymbol .GetAttributes() diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index c16052b..dff5e74 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -15,7 +15,7 @@ ClassDeclarationSyntax classSyntax /// This value is typically derived from the provided generation attribute or defaults /// to the containing namespace of the type symbol. /// - public string NamespaceName { get; } = + public string NamespaceName { get; } = PrepareValue( generationAttribute, AutomaticInterfaceGenerator.NamespaceParameterName, @@ -27,7 +27,7 @@ ClassDeclarationSyntax classSyntax /// is derived from the class name, prefixed with 'I', unless overridden by a specific /// attribute value during generation. /// - public string InterfaceName { get; } = + public string InterfaceName { get; } = PrepareValue(generationAttribute, AutomaticInterfaceGenerator.InterfaceParameterName, $"I{classSyntax.GetClassName()}" From 6802f64663ba5e6c512381fd973acf6bdf9ec885 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:52:09 -0700 Subject: [PATCH 11/12] [CF] build rules --- AutomaticInterface/AutomaticInterface/Builder.cs | 2 +- .../AutomaticInterface/GeneratedSymbolDetails.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index e329136..a725079 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -81,7 +81,7 @@ is not ClassDeclarationSyntax classSyntax private static GeneratedSymbolDetails GetSymbolDetails( ITypeSymbol typeSymbol, ClassDeclarationSyntax classSyntax - ) + ) { var generationAttribute = typeSymbol .GetAttributes() diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index dff5e74..f78fea2 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -20,7 +20,7 @@ ClassDeclarationSyntax classSyntax generationAttribute, AutomaticInterfaceGenerator.NamespaceParameterName, typeSymbol.ContainingNamespace.ToDisplayString() - ); + ); /// /// Represents the name of the interface generated for a class. The interface name @@ -31,7 +31,7 @@ ClassDeclarationSyntax classSyntax PrepareValue(generationAttribute, AutomaticInterfaceGenerator.InterfaceParameterName, $"I{classSyntax.GetClassName()}" - ); + ); private static string PrepareValue(AttributeData? generationAttribute, string key, string defaultValue) { From 99e24d304ab9b37cedc7f1b84ebaf3d123fcbc1e Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Wed, 23 Apr 2025 18:54:44 -0700 Subject: [PATCH 12/12] [CF] build rules --- .../GeneratedSymbolDetails.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs index f78fea2..b0c63d9 100644 --- a/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs +++ b/AutomaticInterface/AutomaticInterface/GeneratedSymbolDetails.cs @@ -28,18 +28,27 @@ ClassDeclarationSyntax classSyntax /// attribute value during generation. /// public string InterfaceName { get; } = - PrepareValue(generationAttribute, + PrepareValue( + generationAttribute, AutomaticInterfaceGenerator.InterfaceParameterName, $"I{classSyntax.GetClassName()}" ); - private static string PrepareValue(AttributeData? generationAttribute, string key, string defaultValue) + private static string PrepareValue( + AttributeData? generationAttribute, + string key, + string defaultValue + ) { - var parameterSymbol = generationAttribute?.AttributeConstructor?.Parameters.SingleOrDefault(x => x.Name == key); + var parameterSymbol = generationAttribute?.AttributeConstructor?.Parameters.SingleOrDefault( + x => x.Name == key + ); if (parameterSymbol != null) { - var index = generationAttribute!.AttributeConstructor!.Parameters.IndexOf(parameterSymbol); + var index = generationAttribute!.AttributeConstructor!.Parameters.IndexOf( + parameterSymbol + ); var result = generationAttribute.ConstructorArguments[index].Value!.ToString(); if (!string.IsNullOrWhiteSpace(result)) {