diff --git a/Generate-ReleaseNotes.bat b/Generate-ReleaseNotes.bat new file mode 100644 index 0000000..4c5f50b --- /dev/null +++ b/Generate-ReleaseNotes.bat @@ -0,0 +1,7 @@ +rem https://github.com/StefH/GitHubReleaseNotes + +SET version=0.0.10 + +GitHubReleaseNotes --output "ReleaseNotes.md" --skip-empty-releases --exclude-labels question invalid doc --version %version% + +GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc --template PackageReleaseNotes.template --version %version% \ No newline at end of file diff --git a/GitHubReleaseNotes.txt b/GitHubReleaseNotes.txt deleted file mode 100644 index 7c55da5..0000000 --- a/GitHubReleaseNotes.txt +++ /dev/null @@ -1,3 +0,0 @@ -https://github.com/StefH/GitHubReleaseNotes - -GitHubReleaseNotes --output ReleaseNotes.md --skip-empty-releases --exclude-labels question invalid doc --version 0.0.10 \ No newline at end of file diff --git a/PackageReadme.md b/PackageReadme.md new file mode 100644 index 0000000..0d61f17 --- /dev/null +++ b/PackageReadme.md @@ -0,0 +1,68 @@ +# Usage + +**Given: an external existing class which does not implement an interface** +``` c# +public sealed class Person +{ + public string Name { get; set; } + + public string HelloWorld(string name) + { + return $"Hello {name} !"; + } +} +``` + +**Create a partial interface** +And annotate this with `ProxyInterfaceGenerator.Proxy[...]` and with the Type which needs to be wrapped: + +``` c# +[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.Person))] +public partial interface IPerson +{ +} +``` + +When the code is compiled, this source generator creates the following two items: + +**1. An additional partial interface** +Which defines the same properties and methods as in the external class. +``` c# +public partial interface IPerson +{ + string Name { get; set; } + + string HelloWorld(string name); +} +``` + +**2. A Proxy class** +Which takes the external class in the constructor and wraps all properties and methods. + +``` c# +public class PersonProxy : IPerson +{ + public Person _Instance { get; } + + public PersonProxy(Person instance) + { + _Instance = instance; + } + + public string Name { get => _Instance.Name; set => _Instance.Name = value; } + + public string HelloWorld(string name) + { + string name_ = name; + var result_19479959 = _Instance.HelloWorld(name_); + return result_19479959; + } +} +``` + +## Use it +``` c# +IPerson p = new PersonProxy(new Person()); +p.Name = "test"; +p.HelloWorld("stef"); +``` \ No newline at end of file diff --git a/PackageReleaseNotes.template b/PackageReleaseNotes.template new file mode 100644 index 0000000..c07b1ac --- /dev/null +++ b/PackageReleaseNotes.template @@ -0,0 +1,6 @@ +# {{releaseInfos.0.FriendlyName}} ({{formatDate releaseInfos.0.When "dd MMMM yyyy"}}) +{{#each releaseInfos.0.issueInfos}} +- #{{Number}} {{Title}}{{#if Labels}} [{{join Labels ", "}}]{{/if}} +{{/each}} + +The full release notes can be found here: https://github.com/StefH/ProxyInterfaceSourceGenerator/blob/main/ReleaseNotes.md \ No newline at end of file diff --git a/PackageReleaseNotes.txt b/PackageReleaseNotes.txt new file mode 100644 index 0000000..6889888 --- /dev/null +++ b/PackageReleaseNotes.txt @@ -0,0 +1,5 @@ +# 0.0.10 (06 August 2021) +- #25 Fix support for Nullable (language version 8) [bug] +- #14 for projects where #nullable is disabled emitting nullable reftype without preprocessor '#nullable enable' would result in compile time error. [bug] + +The full release notes can be found here: https://github.com/StefH/ProxyInterfaceSourceGenerator/blob/main/ReleaseNotes.md \ No newline at end of file diff --git a/ProxyInterfaceSourceGenerator Solution.sln b/ProxyInterfaceSourceGenerator Solution.sln index b7fd5e6..5accc75 100644 --- a/ProxyInterfaceSourceGenerator Solution.sln +++ b/ProxyInterfaceSourceGenerator Solution.sln @@ -8,7 +8,10 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2CE637DC-E8F5-4603-8B57-E51A32F631F1}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - GitHubReleaseNotes.txt = GitHubReleaseNotes.txt + Generate-ReleaseNotes.bat = Generate-ReleaseNotes.bat + PackageReadme.md = PackageReadme.md + PackageReleaseNotes.template = PackageReleaseNotes.template + PackageReleaseNotes.txt = PackageReleaseNotes.txt README.md = README.md ReleaseNotes.md = ReleaseNotes.md EndProjectSection diff --git a/src/ProxyInterfaceSourceGenerator/Context.cs b/src/ProxyInterfaceSourceGenerator/Context.cs index 8c7b67b..65c3914 100644 --- a/src/ProxyInterfaceSourceGenerator/Context.cs +++ b/src/ProxyInterfaceSourceGenerator/Context.cs @@ -11,7 +11,7 @@ namespace ProxyInterfaceSourceGenerator // public List GeneratedData { get; } = new List(); - public IDictionary CandidateInterfaces { get; init; } + public IDictionary CandidateInterfaces { get; init; } = default!; public Dictionary ReplacedTypes { get; } = new Dictionary(); } diff --git a/src/ProxyInterfaceSourceGenerator/ContextData.cs b/src/ProxyInterfaceSourceGenerator/ContextData.cs index df25eb5..301062f 100644 --- a/src/ProxyInterfaceSourceGenerator/ContextData.cs +++ b/src/ProxyInterfaceSourceGenerator/ContextData.cs @@ -8,6 +8,6 @@ namespace ProxyInterfaceSourceGenerator public string? ClassName { get; init; } - public FileData FileData { get; init; } + public FileData FileData { get; init; } = default!; } } \ No newline at end of file diff --git a/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj b/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj index b4f32d3..ce2dc38 100644 --- a/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj +++ b/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj @@ -1,8 +1,9 @@ - + - 0.0.10 + 0.0.10-preview-01 netstandard2.0 + {12344228-91F4-4502-9595-39584E5ABB34} 9 enable Stef Heyenrath @@ -13,13 +14,11 @@ class;interface;proxy;SourceGenerator;Analyzer;Generation;Generate;wrap MIT - See ReleaseNotes.md + $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../../PackageReleaseNotes.txt")) https://github.com/StefH/ProxyInterfaceGenerator git https://github.com/StefH/ProxyInterfaceGenerator - - netstandard2.0 - {12344228-91F4-4502-9595-39584E5ABB34} + PackageReadme.md false true @@ -30,6 +29,10 @@ true + + + +