From 4a05260d5112022107a8d9c57825d2f8ef5e6e96 Mon Sep 17 00:00:00 2001 From: FaustVX Date: Sun, 19 Nov 2023 15:41:53 +0100 Subject: [PATCH] Bumped version `v1.3.2` --- ConsoleApp1/ConsoleApp1.csproj | 2 +- PrimaryParameter.SG/Generator.cs | 10 ++++++- .../PrimaryParameter.SG.csproj | 2 +- .../PrimaryParameterSnapshotTests.cs | 28 ++++++++++++++----- .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- .../DontUseAttribute.g.verified.cs | 11 ++++++++ .../FaustVX.PrimaryParameter.SG.g.verified.cs | 1 + .../FieldAttribute.g.verified.cs | 15 ++++++++++ .../PropertyAttribute.g.verified.cs | 15 ++++++++++ .../RefFieldAttribute.g.verified.cs | 14 ++++++++++ .../FaustVX.PrimaryParameter.SG.g.verified.cs | 4 --- README.md | 3 +- TODO.md | 1 + 18 files changed, 91 insertions(+), 39 deletions(-) create mode 100644 PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/DontUseAttribute.g.verified.cs create mode 100644 PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FaustVX.PrimaryParameter.SG.g.verified.cs create mode 100644 PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FieldAttribute.g.verified.cs create mode 100644 PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/PropertyAttribute.g.verified.cs create mode 100644 PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/RefFieldAttribute.g.verified.cs diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj index ca5ad1a..5e57479 100644 --- a/ConsoleApp1/ConsoleApp1.csproj +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -19,7 +19,7 @@ - + diff --git a/PrimaryParameter.SG/Generator.cs b/PrimaryParameter.SG/Generator.cs index 4f77a15..edf701e 100644 --- a/PrimaryParameter.SG/Generator.cs +++ b/PrimaryParameter.SG/Generator.cs @@ -381,7 +381,15 @@ static IEnumerable GetTypesToGenerate(Compilation compilation, IEnume } static void GenerateFiles(IEnumerable parameters, SourceProductionContext context) - => context.AddSource("FaustVX.PrimaryParameter.SG.g.cs", string.Concat(parameters.Select(static item => GetResource(item.Namespace, item.TypeName, item.FieldNames.Select(n => n.GenerateMember(item)))))); + { + context.AddSource("FaustVX.PrimaryParameter.SG.g.cs", string.Concat(parameters.Where(Where).Select(Select))); + + static bool Where(Parameter parameter) + => parameter.FieldNames.Length > 0; + + static string Select(Parameter parameter) + => GetResource(parameter.Namespace, parameter.TypeName, parameter.FieldNames.Select(n => n.GenerateMember(parameter))); + } static string GetResource(string nameSpace, ParentClass? parentClass, IEnumerable inner) { diff --git a/PrimaryParameter.SG/PrimaryParameter.SG.csproj b/PrimaryParameter.SG/PrimaryParameter.SG.csproj index 27c9d8b..1d8be7f 100644 --- a/PrimaryParameter.SG/PrimaryParameter.SG.csproj +++ b/PrimaryParameter.SG/PrimaryParameter.SG.csproj @@ -31,7 +31,7 @@ netstandard2.0 FaustVX.PrimaryParameter.SG - 1.3.1 + 1.3.2 FaustVX https://github.com/FaustVX/PrimaryParameter git diff --git a/PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs b/PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs index ceac184..244c492 100644 --- a/PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs +++ b/PrimaryParameter.Tests/PrimaryParameterSnapshotTests.cs @@ -147,7 +147,7 @@ public Task GeneratesPC01WithDontUse() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse] int i) + public class C([DontUse] int i) { int M() => i; } @@ -163,7 +163,7 @@ public Task DontGeneratesPC01WithDontUseOnMember_Simple() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse(AllowInMemberInit = true)] int i) + public class C([DontUse(AllowInMemberInit = true)] int i) { int M = i; } @@ -179,7 +179,7 @@ public Task DontGeneratesPC01WithDontUseOnMember_Complex() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse(AllowInMemberInit = true)] int i) + public class C([DontUse(AllowInMemberInit = true)] int i) { string L = i.ToString(); } @@ -195,7 +195,7 @@ public Task DontGeneratesPC01WithDontUseOnPropertyInitializer() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse(AllowInMemberInit = true)] int i) + public class C([DontUse(AllowInMemberInit = true)] int i) { string L { get; } = i.ToString(); } @@ -211,7 +211,7 @@ public Task DoGeneratesPC01WithDontUseOnPropertyBody() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse] int i) + public class C([DontUse] int i) { int M => i; } @@ -227,7 +227,7 @@ public Task DoGeneratesPC01WithDontUseOnPropertyGet() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse] int i) + public class C([DontUse] int i) { int M { @@ -246,7 +246,7 @@ public Task DoGeneratesPC01WithDontUseOnMember() // The source code to test var source = """ using PrimaryParameter.SG; - public partial class C([DontUse(AllowInMemberInit = false)] int i) + public class C([DontUse(AllowInMemberInit = false)] int i) { int M = i; } @@ -255,4 +255,18 @@ public partial class C([DontUse(AllowInMemberInit = false)] int i) // Pass the source code to our helper and snapshot test the output return TestHelper.Verify(source); } + + [Fact] + public Task DontNeedPartialModifierOnType() + { + // The source code to test + var source = """ + using PrimaryParameter.SG; + public class C([DontUse] int i) + { } + """; + + // Pass the source code to our helper and snapshot test the output + return TestHelper.Verify(source); + } } diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnMember/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnMember/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnMember/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnMember/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyBody/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyBody/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyBody/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyBody/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyGet/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyGet/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyGet/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DoGeneratesPC01WithDontUseOnPropertyGet/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Complex/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Complex/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Complex/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Complex/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Simple/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Simple/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Simple/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnMember_Simple/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnPropertyInitializer/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnPropertyInitializer/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnPropertyInitializer/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontGeneratesPC01WithDontUseOnPropertyInitializer/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/DontUseAttribute.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/DontUseAttribute.g.verified.cs new file mode 100644 index 0000000..56e9a73 --- /dev/null +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/DontUseAttribute.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: DontUseAttribute.g.cs +// +using global::System; +namespace PrimaryParameter.SG +{ + [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)] + sealed class DontUseAttribute : Attribute + { + public bool AllowInMemberInit { get; init; } + } +} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FaustVX.PrimaryParameter.SG.g.verified.cs new file mode 100644 index 0000000..2aa2d2b --- /dev/null +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -0,0 +1 @@ +//HintName: FaustVX.PrimaryParameter.SG.g.cs diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FieldAttribute.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FieldAttribute.g.verified.cs new file mode 100644 index 0000000..04cf719 --- /dev/null +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/FieldAttribute.g.verified.cs @@ -0,0 +1,15 @@ +//HintName: FieldAttribute.g.cs +// +using global::System; +namespace PrimaryParameter.SG +{ + [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)] + sealed class FieldAttribute : Attribute + { + public string Name { get; init; } + public string AssignFormat { get; init; } + public Type Type { get; init; } + public bool IsReadonly { get; init; } + public string Scope { get; init; } + } +} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/PropertyAttribute.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/PropertyAttribute.g.verified.cs new file mode 100644 index 0000000..df9d231 --- /dev/null +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/PropertyAttribute.g.verified.cs @@ -0,0 +1,15 @@ +//HintName: PropertyAttribute.g.cs +// +using global::System; +namespace PrimaryParameter.SG +{ + [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)] + sealed class PropertyAttribute : Attribute + { + public string Name { get; init; } + public string AssignFormat { get; init; } + public Type Type { get; init; } + public string Setter { get; init; } + public string Scope { get; init; } + } +} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/RefFieldAttribute.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/RefFieldAttribute.g.verified.cs new file mode 100644 index 0000000..96fa41e --- /dev/null +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.DontNeedPartialModifierOnType/RefFieldAttribute.g.verified.cs @@ -0,0 +1,14 @@ +//HintName: RefFieldAttribute.g.cs +// +using global::System; +namespace PrimaryParameter.SG +{ + [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = true)] + sealed class RefFieldAttribute : Attribute + { + public string Name { get; init; } + public string Scope { get; init; } + public bool IsReadonlyRef { get; init; } + public bool IsRefReadonly { get; init; } + } +} diff --git a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.GeneratesPC01WithDontUse/FaustVX.PrimaryParameter.SG.g.verified.cs b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.GeneratesPC01WithDontUse/FaustVX.PrimaryParameter.SG.g.verified.cs index 6fe066d..2aa2d2b 100644 --- a/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.GeneratesPC01WithDontUse/FaustVX.PrimaryParameter.SG.g.verified.cs +++ b/PrimaryParameter.Tests/Verify/PrimaryParameterSnapshotTests.GeneratesPC01WithDontUse/FaustVX.PrimaryParameter.SG.g.verified.cs @@ -1,5 +1 @@ //HintName: FaustVX.PrimaryParameter.SG.g.cs -// -partial class C -{ -} diff --git a/README.md b/README.md index 30d96e6..340d04f 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,8 @@ You can type as many attributes as you want on a single parameter (Except for `D ## Versions |Version|Date|Comments| |-------|----|--------| -|v1.3.1|25/08/2023|fix a bug with member initialization| +|v1.3.2|19/11/2023|Don't generate the partial generated type if not needed| +|v1.3.1|19/11/2023|Fix a bug with member initialization| |v1.3.0|19/11/2023|Added `DontUseAttribute`
Add a code-fix for `CS0282`
Changed `PropertyAttribute.WithInit` to `PropertyAttribute.Setter`| |v1.2.0|25/08/2023|Support for default values customization| |v1.1.0|15/08/2023|[dotnet/roslyn#67371](https://github.com/dotnet/roslyn/issues/67371) fixed
(related to `v0.4.6`)| diff --git a/TODO.md b/TODO.md index 3c603dc..4452a41 100644 --- a/TODO.md +++ b/TODO.md @@ -10,3 +10,4 @@ - `set` - `init` - [x] Add `// ` in `FaustVX.PrimaryParameter.SG.g.cs` +- [x] Don't generate empty partial types