From 8728df6d6d93341501b93817d732d12c9bb3eae6 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Mon, 4 Nov 2024 09:19:08 -0800 Subject: [PATCH 1/6] Fixes #75: Improves inheritdoc so that developer documentation is properly referenced on the autogenerated interfaces --- .../AutomaticInterface/Builder.cs | 20 +++--- .../DemoClassWithCustomNamespace.cs | 9 ++- .../Tests/GeneratorTests.Properties.cs | 22 +++--- .../Tests/GeneratorTests.TypeResolution.cs | 16 ++--- AutomaticInterface/Tests/GeneratorTests.cs | 72 +++++++++---------- .../Tests/GeneratorsTests.MethodParameters.cs | 6 +- 6 files changed, 74 insertions(+), 71 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index a75cd87..6559aa0 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -9,13 +9,13 @@ namespace AutomaticInterface; public static class Builder { - private const string InheritDoc = "/// "; // we use inherit doc because that should be able to fetch documentation from base classes. + private static string InheritDoc(string source) => $"/// "; // we use inherit doc because that should be able to fetch documentation from base classes. private static readonly SymbolDisplayFormat MethodSignatureDisplayFormat = new( memberOptions: SymbolDisplayMemberOptions.IncludeParameters, parameterOptions: SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeParamsRefOut ); private static readonly SymbolDisplayFormat TypeDisplayFormat = @@ -24,7 +24,7 @@ public static class Builder typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier ); public static string BuildInterfaceFor(ITypeSymbol typeSymbol) @@ -67,6 +67,7 @@ private static string GetNameSpace(ISymbol typeSymbol) { return typeSymbol.ContainingNamespace.ToDisplayString(); } + var customNs = generationAttribute.ConstructorArguments.FirstOrDefault().Value?.ToString(); return string.IsNullOrWhiteSpace(customNs) @@ -92,10 +93,7 @@ InterfaceBuilder codeGenerator .GroupBy(x => x.ToDisplayString(MethodSignatureDisplayFormat)) .Select(g => g.First()) .ToList() - .ForEach(method => - { - AddMethod(codeGenerator, method); - }); + .ForEach(method => { AddMethod(codeGenerator, method); }); } private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol method) @@ -117,7 +115,7 @@ private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol meth codeGenerator.AddMethodToInterface( name, returnType.ToDisplayString(TypeDisplayFormat), - InheritDoc, + InheritDoc(method.ToDisplayString()), paramResult, typedArgs ); @@ -197,7 +195,7 @@ InterfaceBuilder codeGenerator codeGenerator.AddEventToInterface( name, type.ToDisplayString(TypeDisplayFormat), - InheritDoc + InheritDoc(evt.ToDisplayString()) ); }); } @@ -285,7 +283,7 @@ InterfaceBuilder interfaceGenerator hasGet, hasSet, isRef, - InheritDoc + InheritDoc(prop.ToDisplayString()) ); }); } @@ -351,4 +349,4 @@ private static string GetGeneric(TypeDeclarationSyntax classSyntax) return formattedGeneric; } -} +} \ No newline at end of file diff --git a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs index cb61b27..f64f434 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs @@ -15,6 +15,11 @@ namespace AutomaticInterfaceExample )] public class DemoClass2 : IDemoClass2 { - public void Test() { } + /// + /// This is a test method + /// + public void Test() + { + } } -} +} \ No newline at end of file diff --git a/AutomaticInterface/Tests/GeneratorTests.Properties.cs b/AutomaticInterface/Tests/GeneratorTests.Properties.cs index 278919a..109bf0c 100644 --- a/AutomaticInterface/Tests/GeneratorTests.Properties.cs +++ b/AutomaticInterface/Tests/GeneratorTests.Properties.cs @@ -39,7 +39,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; } } @@ -85,7 +85,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; } } @@ -139,7 +139,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string? NullableProperty { get; set; } } @@ -195,7 +195,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task NullableProperty { get; set; } } @@ -243,7 +243,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface ISecondClass { - /// + /// int AProperty { get; set; } } @@ -288,7 +288,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string SomeProperty { get; set; } } @@ -334,7 +334,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string SomeProperty { get; set; } } @@ -377,7 +377,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; set; } } @@ -421,7 +421,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { set; } } @@ -465,7 +465,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; } } @@ -508,7 +508,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; init; } } diff --git a/AutomaticInterface/Tests/GeneratorTests.TypeResolution.cs b/AutomaticInterface/Tests/GeneratorTests.TypeResolution.cs index 97710c3..23af505 100644 --- a/AutomaticInterface/Tests/GeneratorTests.TypeResolution.cs +++ b/AutomaticInterface/Tests/GeneratorTests.TypeResolution.cs @@ -35,7 +35,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; set; } } @@ -77,7 +77,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; set; } } @@ -120,7 +120,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task Hello { get; set; } } @@ -169,10 +169,10 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IModelManager { - /// + /// global::AutomaticInterfaceExample.Models1.Model GetModel1(); - /// + /// global::AutomaticInterfaceExample.Models2.Model GetModel2(); } @@ -222,7 +222,7 @@ namespace RootNamespace.ModelManager [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IModelManager { - /// + /// global::RootNamespace.Models.Model GetModel(); } @@ -268,7 +268,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task GetTask(); } @@ -314,7 +314,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::GlobalNamespace.AClass GetClass(); } diff --git a/AutomaticInterface/Tests/GeneratorTests.cs b/AutomaticInterface/Tests/GeneratorTests.cs index 9367e9a..7f829df 100644 --- a/AutomaticInterface/Tests/GeneratorTests.cs +++ b/AutomaticInterface/Tests/GeneratorTests.cs @@ -87,7 +87,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// bool TryStartTransaction(string file = "", string member = "", int line = 0, bool notify = true); } @@ -136,7 +136,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// bool TryStartTransaction(global::AutomaticInterfaceExample.MyStruct data = default(global::AutomaticInterfaceExample.MyStruct)); } @@ -180,7 +180,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// bool TryStartTransaction(string data = null); } @@ -263,7 +263,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(); } @@ -308,7 +308,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task Hello(); } @@ -353,7 +353,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(string x); } @@ -398,7 +398,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(global::System.Threading.Tasks.Task x); } @@ -442,7 +442,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(string x, int y, double z); } @@ -577,7 +577,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(string x); } @@ -625,7 +625,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(string x); } @@ -673,7 +673,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; } } @@ -726,7 +726,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; } } @@ -875,7 +875,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// event global::System.EventHandler ShapeChanged; } @@ -1021,16 +1021,16 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; set; } - /// + /// string OnlyGet { get; } - /// + /// string AMethod(string x, string y); - /// + /// event global::System.EventHandler ShapeChanged; } @@ -1080,7 +1080,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string CMethod(string x, string y) where T : class where T1 : struct where T3 : global::AutomaticInterfaceExample.DemoClass where T4 : IDemoClass; } @@ -1131,10 +1131,10 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string AMethod(string x, string y); - /// + /// string AMethod(string x, string y, string crash); } @@ -1177,7 +1177,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string AMethod(global::AutomaticInterfaceExample.DemoClass? x, string y); } @@ -1221,7 +1221,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string? AMethod(global::AutomaticInterfaceExample.DemoClass x, string y); } @@ -1276,7 +1276,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// event global::System.EventHandler? ShapeChangedNullable; } @@ -1331,7 +1331,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// event global::System.EventHandler ShapeChangedNullable; } @@ -1396,7 +1396,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task GetFinalDocumentsByIDFails(string agreementID, string docType, bool amt = false, bool? attachSupportingDocuments = true, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)); } @@ -1461,7 +1461,7 @@ namespace CustomNameSpace [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task GetFinalDocumentsByIDFails(string agreementID, string docType, bool amt = false, bool? attachSupportingDocuments = true, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)); } @@ -1507,7 +1507,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// global::System.Threading.Tasks.Task AMethodAsync(global::AutomaticInterfaceExample.DemoClass x, string y); } @@ -1553,7 +1553,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string AMethod(global::System.Threading.Tasks.Task x, string y); } @@ -1596,7 +1596,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// ref string AProperty { get; } } @@ -1639,7 +1639,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// void AMethod(int @event); } @@ -1685,7 +1685,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// bool AMethod(); } @@ -1731,7 +1731,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// bool AMethod(); } @@ -1774,10 +1774,10 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// void AMethod(int val); - /// + /// void AMethod(ref int val); } @@ -1824,7 +1824,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// event global::System.EventHandler AnEvent; } @@ -1871,7 +1871,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// event global::System.EventHandler AnEvent; } diff --git a/AutomaticInterface/Tests/GeneratorsTests.MethodParameters.cs b/AutomaticInterface/Tests/GeneratorsTests.MethodParameters.cs index 9b94df0..a7b3465 100644 --- a/AutomaticInterface/Tests/GeneratorsTests.MethodParameters.cs +++ b/AutomaticInterface/Tests/GeneratorsTests.MethodParameters.cs @@ -39,7 +39,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// void AMethod(out int someOutParameter); } @@ -82,7 +82,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// void AMethod(in int someOutParameter); } @@ -125,7 +125,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// void AMethod(ref int someOutParameter); } From 980b382e19353c3a39037e184d5db6b5ec55d8d9 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Mon, 4 Nov 2024 11:31:34 -0800 Subject: [PATCH 2/6] [CF] checkpoint --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 57e9758..a97741d 100644 --- a/README.md +++ b/README.md @@ -105,28 +105,28 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello { get; set; } - /// + /// string OnlyGet { get; } - /// + /// string AMethod(string x, string y); - /// - string CMethod(string? x, string y) where T : class where T1 : struct where T3 : DemoClass where T4 : IDemoClass; + /// + string CMethod(string? x, string y) where T : class where T1 : struct where T3 : global::AutomaticInterfaceExample.DemoClass where T4 : IDemoClass; - /// + /// global::System.Threading.Tasks.Task ASync(string x, string y); - /// + /// event global::System.EventHandler ShapeChanged; - /// + /// event global::System.EventHandler? ShapeChangedNullable; - /// + /// event global::System.EventHandler ShapeChangedNullable2; } From cf14e71f9929587449c2b8c2eadaa96424b8cdcd Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Mon, 4 Nov 2024 13:15:54 -0800 Subject: [PATCH 3/6] fixed generic documentation --- AutomaticInterface/AutomaticInterface/Builder.cs | 2 +- .../AutomaticInterfaceExample/DemoClass.cs | 11 +++++++++++ .../AutomaticInterfaceExample/Program.cs | 3 ++- AutomaticInterface/Tests/GeneratorTests.cs | 6 +++--- README.md | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 6559aa0..b67e9e4 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -9,7 +9,7 @@ namespace AutomaticInterface; public static class Builder { - private static string InheritDoc(string source) => $"/// "; // we use inherit doc because that should be able to fetch documentation from base classes. + private static string InheritDoc(string source) => $"/// ', '}')}\" />"; // we use inherit doc because that should be able to fetch documentation from base classes. private static readonly SymbolDisplayFormat MethodSignatureDisplayFormat = new( diff --git a/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs b/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs index 07e9b82..6fc8cc4 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs @@ -38,6 +38,17 @@ private string BMethod(string x, string y) // ignored because not public return x + y; } + /// + /// CMethod allows operations with multiple generic type parameters and string inputs. + /// + /// The first generic type parameter which must be a class. + /// The second generic type parameter which must be a structure. + /// The third generic type parameter. + /// The fourth generic type parameter which must be derived from DemoClass. + /// The fifth generic type parameter which must implement IDemoClass. + /// The optional first string input parameter. + /// The second string input parameter. + /// Returns a string result. public string CMethod(string? x, string y) // included where T : class where T1 : struct diff --git a/AutomaticInterface/AutomaticInterfaceExample/Program.cs b/AutomaticInterface/AutomaticInterfaceExample/Program.cs index 0745142..380e325 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/Program.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/Program.cs @@ -15,7 +15,8 @@ static void Main(string[] args) IDemoClass demoInterface = demo; Console.WriteLine(demoInterface.AMethod("A", "B")); + Console.WriteLine(demoInterface.CMethod("A", "B")); Console.WriteLine("Hello World!"); } } -} +} \ No newline at end of file diff --git a/AutomaticInterface/Tests/GeneratorTests.cs b/AutomaticInterface/Tests/GeneratorTests.cs index 7f829df..db8824e 100644 --- a/AutomaticInterface/Tests/GeneratorTests.cs +++ b/AutomaticInterface/Tests/GeneratorTests.cs @@ -398,7 +398,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string Hello(global::System.Threading.Tasks.Task x); } @@ -1080,7 +1080,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string CMethod(string x, string y) where T : class where T1 : struct where T3 : global::AutomaticInterfaceExample.DemoClass where T4 : IDemoClass; } @@ -1553,7 +1553,7 @@ namespace AutomaticInterfaceExample [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// + /// string AMethod(global::System.Threading.Tasks.Task x, string y); } diff --git a/README.md b/README.md index a97741d..0481f3e 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ namespace AutomaticInterfaceExample /// string AMethod(string x, string y); - /// + /// string CMethod(string? x, string y) where T : class where T1 : struct where T3 : global::AutomaticInterfaceExample.DemoClass where T4 : IDemoClass; /// From 8b5925e7f5f0ec8258e32352a9aa90ae20caa0fc Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Mon, 4 Nov 2024 20:05:57 -0800 Subject: [PATCH 4/6] [CF] checkpoint --- .../AutomaticInterface/Builder.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index b67e9e4..0a29297 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -9,13 +9,14 @@ namespace AutomaticInterface; public static class Builder { - private static string InheritDoc(string source) => $"/// ', '}')}\" />"; // we use inherit doc because that should be able to fetch documentation from base classes. + private static string InheritDoc(ISymbol source) => + $"/// ', '}')}\" />"; // we use inherit doc because that should be able to fetch documentation from base classes. private static readonly SymbolDisplayFormat MethodSignatureDisplayFormat = new( memberOptions: SymbolDisplayMemberOptions.IncludeParameters, parameterOptions: SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeParamsRefOut ); private static readonly SymbolDisplayFormat TypeDisplayFormat = @@ -24,7 +25,7 @@ public static class Builder typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier ); public static string BuildInterfaceFor(ITypeSymbol typeSymbol) @@ -93,7 +94,7 @@ InterfaceBuilder codeGenerator .GroupBy(x => x.ToDisplayString(MethodSignatureDisplayFormat)) .Select(g => g.First()) .ToList() - .ForEach(method => { AddMethod(codeGenerator, method); }); + .ForEach(method => AddMethod(codeGenerator, method)); } private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol method) @@ -115,7 +116,7 @@ private static void AddMethod(InterfaceBuilder codeGenerator, IMethodSymbol meth codeGenerator.AddMethodToInterface( name, returnType.ToDisplayString(TypeDisplayFormat), - InheritDoc(method.ToDisplayString()), + InheritDoc(method), paramResult, typedArgs ); @@ -195,7 +196,7 @@ InterfaceBuilder codeGenerator codeGenerator.AddEventToInterface( name, type.ToDisplayString(TypeDisplayFormat), - InheritDoc(evt.ToDisplayString()) + InheritDoc(evt) ); }); } @@ -283,7 +284,7 @@ InterfaceBuilder interfaceGenerator hasGet, hasSet, isRef, - InheritDoc(prop.ToDisplayString()) + InheritDoc(prop) ); }); } @@ -349,4 +350,4 @@ private static string GetGeneric(TypeDeclarationSyntax classSyntax) return formattedGeneric; } -} \ No newline at end of file +} From 9beac5c4cb1a9bec6e6fb72b4b894af0ff6b7314 Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Mon, 4 Nov 2024 22:27:23 -0800 Subject: [PATCH 5/6] [CF] csharpier --- .../AutomaticInterface/Builder.cs | 19 +++++++++---------- .../AutomaticInterface/InterfaceBuilder.cs | 2 +- .../DemoClassWithCustomNamespace.cs | 6 ++---- .../AutomaticInterfaceExample/Program.cs | 6 ++++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index 0a29297..d9a64a0 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -222,10 +222,10 @@ private static string GetMethodOptionalValue(IParameterSymbol x) string => $" = \"{x.ExplicitDefaultValue}\"", bool value => $" = {(value ? "true" : "false")}", // struct - null when x.Type.IsValueType - => $" = default({x.Type.ToDisplayString(TypeDisplayFormat)})", + null when x.Type.IsValueType => + $" = default({x.Type.ToDisplayString(TypeDisplayFormat)})", null => " = null", - _ => $" = {x.ExplicitDefaultValue}" + _ => $" = {x.ExplicitDefaultValue}", }; } @@ -294,12 +294,11 @@ private static PropertySetKind GetSetKind(IMethodSymbol? setMethodSymbol) return setMethodSymbol switch { null => PropertySetKind.NoSet, - { IsInitOnly: true, DeclaredAccessibility: Accessibility.Public } - => PropertySetKind.Init, - _ - => setMethodSymbol is { DeclaredAccessibility: Accessibility.Public } - ? PropertySetKind.Always - : PropertySetKind.NoSet + { IsInitOnly: true, DeclaredAccessibility: Accessibility.Public } => + PropertySetKind.Init, + _ => setMethodSymbol is { DeclaredAccessibility: Accessibility.Public } + ? PropertySetKind.Always + : PropertySetKind.NoSet, }; } @@ -327,7 +326,7 @@ private static string GetDocumentationForClass(CSharpSyntaxNode classSyntax) SyntaxKind.DocumentationCommentExteriorTrivia, SyntaxKind.EndOfDocumentationCommentToken, SyntaxKind.MultiLineDocumentationCommentTrivia, - SyntaxKind.SingleLineDocumentationCommentTrivia + SyntaxKind.SingleLineDocumentationCommentTrivia, ]; var trivia = classSyntax diff --git a/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs b/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs index 41a9715..2e60a05 100644 --- a/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs +++ b/AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs @@ -153,7 +153,7 @@ private static string GetSet(PropertySetKind propSetKind) PropertySetKind.NoSet => string.Empty, PropertySetKind.Always => "set; ", PropertySetKind.Init => "init; ", - _ => throw new ArgumentOutOfRangeException(nameof(propSetKind), propSetKind, null) + _ => throw new ArgumentOutOfRangeException(nameof(propSetKind), propSetKind, null), }; } diff --git a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs index f64f434..1924a5e 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/DemoClassWithCustomNamespace.cs @@ -18,8 +18,6 @@ public class DemoClass2 : IDemoClass2 /// /// This is a test method /// - public void Test() - { - } + public void Test() { } } -} \ No newline at end of file +} diff --git a/AutomaticInterface/AutomaticInterfaceExample/Program.cs b/AutomaticInterface/AutomaticInterfaceExample/Program.cs index 380e325..5e9c15d 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/Program.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/Program.cs @@ -15,8 +15,10 @@ static void Main(string[] args) IDemoClass demoInterface = demo; Console.WriteLine(demoInterface.AMethod("A", "B")); - Console.WriteLine(demoInterface.CMethod("A", "B")); + Console.WriteLine( + demoInterface.CMethod("A", "B") + ); Console.WriteLine("Hello World!"); } } -} \ No newline at end of file +} From 8bf5aa3220870f3f3a5187f0c5908fb601be3dec Mon Sep 17 00:00:00 2001 From: Chase Florell Date: Mon, 4 Nov 2024 23:55:51 -0800 Subject: [PATCH 6/6] [CF] manual formatting as csharpier is doing it differently --- AutomaticInterface/AutomaticInterface/Builder.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/AutomaticInterface/AutomaticInterface/Builder.cs b/AutomaticInterface/AutomaticInterface/Builder.cs index d9a64a0..18a28c8 100644 --- a/AutomaticInterface/AutomaticInterface/Builder.cs +++ b/AutomaticInterface/AutomaticInterface/Builder.cs @@ -222,8 +222,8 @@ private static string GetMethodOptionalValue(IParameterSymbol x) string => $" = \"{x.ExplicitDefaultValue}\"", bool value => $" = {(value ? "true" : "false")}", // struct - null when x.Type.IsValueType => - $" = default({x.Type.ToDisplayString(TypeDisplayFormat)})", + null when x.Type.IsValueType + => $" = default({x.Type.ToDisplayString(TypeDisplayFormat)})", null => " = null", _ => $" = {x.ExplicitDefaultValue}", }; @@ -294,11 +294,12 @@ private static PropertySetKind GetSetKind(IMethodSymbol? setMethodSymbol) return setMethodSymbol switch { null => PropertySetKind.NoSet, - { IsInitOnly: true, DeclaredAccessibility: Accessibility.Public } => - PropertySetKind.Init, - _ => setMethodSymbol is { DeclaredAccessibility: Accessibility.Public } - ? PropertySetKind.Always - : PropertySetKind.NoSet, + { IsInitOnly: true, DeclaredAccessibility: Accessibility.Public } + => PropertySetKind.Init, + _ + => setMethodSymbol is { DeclaredAccessibility: Accessibility.Public } + ? PropertySetKind.Always + : PropertySetKind.NoSet, }; }