From 0e7fb493f2348636c2259a4276530a29323c22b7 Mon Sep 17 00:00:00 2001 From: Colin Wilmans Date: Thu, 15 Aug 2024 16:34:25 +0200 Subject: [PATCH 1/4] README: Tiny adjustments --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c78106c..1fd6d5a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ namespace AutomaticInterfaceExample public string OnlyGet { get; } // included, get and set are copied to the interface when public [IgnoreAutomaticInterface] - public string OnlyGet { get; } // ignored with help of attribute + public string? AnotherGet { get; } // ignored with help of attribute /// /// Method Documentation will be copied @@ -131,7 +131,7 @@ namespace AutomaticInterfaceExample ## How to use it? 1. Install the nuget: `dotnet add package AutomaticInterface`. -2. Add `using AutomaticInterface;` or (Pro-tip) add `global using AutomaticInterface;` to you GlobalUsings. +2. Add `using AutomaticInterface;` or (Pro-tip) add `global using AutomaticInterface;` to your GlobalUsings. 3. Tag your class with the `[GenerateAutomaticInterface]` attribute. 4. The Interface should now be available. @@ -170,7 +170,7 @@ Please make sure that you run [CSharpier](https://csharpier.com/) on the code fo - mohummedibrahim for code and idea - simonmckenzie for PR - avtc for PR -- crwsolutions for PR +- crwsolutions for PRs - FinnAngelo for PR ## Run tests From 49cbe9f36dbb526402cda115377451c526d44594 Mon Sep 17 00:00:00 2001 From: Colin Wilmans Date: Thu, 15 Aug 2024 16:44:16 +0200 Subject: [PATCH 2/4] DemoClass: Sync DemoClass with documentation (README) --- .../AutomaticInterfaceExample/DemoClass.cs | 11 ++--- README.md | 49 +++++++++++-------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs b/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs index 379d4cf..07e9b82 100644 --- a/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs +++ b/AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs @@ -22,7 +22,8 @@ public class DemoClass : IDemoClass // Generics, including constraints are allow public string OnlyGet { get; } // included, get and set are copied to the interface when public - public string? NullableProperty { get; set; } + [IgnoreAutomaticInterface] + public string? AnotherGet { get; } // ignored with help of attribute /// /// Method Documentation will be copied @@ -46,13 +47,7 @@ public string CMethod(string? x, string y) // included return "Ok"; } - [IgnoreAutomaticInterface] - public string IgnoreMethod(string x, string y) // // ignored because of attribute - { - return BMethod(x, y); - } - - public Task ASync(string x, string y) + public Task ASync(string x, string y) { return Task.FromResult(""); } diff --git a/README.md b/README.md index 1fd6d5a..81bf5ec 100644 --- a/README.md +++ b/README.md @@ -26,15 +26,14 @@ namespace AutomaticInterfaceExample class DemoClass: IDemoClass // You Interface will get the Name I+classname, here IDemoclass. // Generics, including constraints are allowed, too. E.g. MyClass where T: class { - /// /// Property Documentation will be copied /// - public string Hello { get; set; } // included, get and set are copied to the interface when public + 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 - [IgnoreAutomaticInterface] + [IgnoreAutomaticInterface] public string? AnotherGet { get; } // ignored with help of attribute /// @@ -42,14 +41,14 @@ namespace AutomaticInterfaceExample /// public string AMethod(string x, string y) // included { - return BMethod(x,y); + return BMethod(x, y); } private string BMethod(string x, string y) // ignored because not public { return x + y; } - + public string CMethod(string? x, string y) // included where T : class where T1 : struct @@ -59,9 +58,14 @@ namespace AutomaticInterfaceExample return "Ok"; } + public Task ASync(string x, string y) + { + return Task.FromResult(""); + } + public static string StaticProperty => "abc"; // static property, ignored - public static string StaticMethod() // static method, ignored + public static string StaticMethod() // static method, ignored { return "static" + DateTime.Now; } @@ -104,25 +108,30 @@ namespace AutomaticInterfaceExample [GeneratedCode("AutomaticInterface", "")] public partial interface IDemoClass { - /// - /// Property Documentation will be copied - /// + /// string Hello { get; set; } - + + /// string OnlyGet { get; } - - /// - /// Method Documentation will be copied - /// + + /// string AMethod(string x, string y); - + + /// string CMethod(string? x, string y) where T : class where T1 : struct where T3 : DemoClass where T4 : IDemoClass; - - /// - /// event Documentation will be copied - /// + + /// + System.Threading.Tasks.Task ASync(string x, string y); + + /// event System.EventHandler ShapeChanged; - + + /// + event System.EventHandler? ShapeChangedNullable; + + /// + event System.EventHandler ShapeChangedNullable2; + } } #nullable restore From a6f5d14c9c202d3426beaa37a8d6cd86a06ca3b9 Mon Sep 17 00:00:00 2001 From: Colin Wilmans Date: Thu, 15 Aug 2024 16:49:56 +0200 Subject: [PATCH 3/4] TestNuget: Removed manual created attribute. --- .../TestNuget/RemoveThisOnNextVersionAttribute.cs | 14 -------------- AutomaticInterface/TestNuget/TestNuget.csproj | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 AutomaticInterface/TestNuget/RemoveThisOnNextVersionAttribute.cs diff --git a/AutomaticInterface/TestNuget/RemoveThisOnNextVersionAttribute.cs b/AutomaticInterface/TestNuget/RemoveThisOnNextVersionAttribute.cs deleted file mode 100644 index 28c870b..0000000 --- a/AutomaticInterface/TestNuget/RemoveThisOnNextVersionAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace AutomaticInterface -{ - /// - /// Use source generator to automatically create a Interface from this class - /// - [AttributeUsage(AttributeTargets.Class)] - [Obsolete("This attribute is obsolete. Use generated attribute instead.", false)] - internal sealed class GenerateAutomaticInterfaceAttribute : Attribute - { - internal GenerateAutomaticInterfaceAttribute(string namespaceName = "") { } - } -} diff --git a/AutomaticInterface/TestNuget/TestNuget.csproj b/AutomaticInterface/TestNuget/TestNuget.csproj index 7a0c96c..3db3e78 100644 --- a/AutomaticInterface/TestNuget/TestNuget.csproj +++ b/AutomaticInterface/TestNuget/TestNuget.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From aedd8ec016a458a7ca3b9423017e36c9c726b1ea Mon Sep 17 00:00:00 2001 From: Colin Wilmans Date: Thu, 15 Aug 2024 17:00:58 +0200 Subject: [PATCH 4/4] README: Typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81bf5ec..4adc4ce 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ Should be simply a build and run Tests ### 4.1.0 - Adds ability to use `init` in property setters -- + ### 4.0.0 - Breaking change in how generated code qualifies parameters, e.g. `async Task` should no longer generated as `System.Threading.Task`. I hope this does not break things