From 5e9afc1511a7f0eda260fcd33240acbb488a38b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 May 2022 04:09:45 +0000 Subject: [PATCH 1/5] Bump xunit.runner.visualstudio from 2.4.4 to 2.4.5 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.4.4 to 2.4.5. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/commits) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../XmlSchemaClassGenerator.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj index 2c38452e..afb889a7 100644 --- a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj +++ b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj @@ -29,7 +29,7 @@ - + all runtime; build; native; contentfiles; analyzers From 652807fcb9cc84506e9ce76de001acc21c24dcb4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 May 2022 04:10:43 +0000 Subject: [PATCH 2/5] Bump Microsoft.NET.Test.Sdk from 17.1.0 to 17.2.0 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.1.0 to 17.2.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](https://github.com/microsoft/vstest/compare/v17.1.0...v17.2.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../XmlSchemaClassGenerator.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj index afb889a7..9723367c 100644 --- a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj +++ b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj @@ -25,7 +25,7 @@ - + From f305122039ca4b23fd46c2ecda9cf22eda140d69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 May 2022 04:10:34 +0000 Subject: [PATCH 3/5] Bump Microsoft.CodeAnalysis.CSharp from 4.1.0 to 4.2.0 Bumps [Microsoft.CodeAnalysis.CSharp](https://github.com/dotnet/roslyn) from 4.1.0 to 4.2.0. - [Release notes](https://github.com/dotnet/roslyn/releases) - [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md) - [Commits](https://github.com/dotnet/roslyn/compare/v4.1.0...Visual-Studio-2019-Version-16.0-Preview-4.2) --- updated-dependencies: - dependency-name: Microsoft.CodeAnalysis.CSharp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../XmlSchemaClassGenerator.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj index 9723367c..c7e656e8 100644 --- a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj +++ b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj @@ -24,7 +24,7 @@ runtime; build; native; contentfiles; analyzers - + From 59c49c62335a3a1ad3abb8249416cf9d66b0e1da Mon Sep 17 00:00:00 2001 From: jmatss Date: Tue, 17 May 2022 22:40:53 +0200 Subject: [PATCH 4/5] Fix invalid interface generated for attribute group Fixes some instances when a invalid interface was generated for attribute groups containing a attribute with a `list` type. Correct logic was already implemented in the function used to generate interfaces for "normal" groups. This logic was moved to a property so that it can be used for both attribute groups and "normal" groups. fixes #325 --- XmlSchemaClassGenerator/TypeModel.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 3bac6eef..5620a7d4 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -781,6 +781,15 @@ private bool IsList } } + private bool IsPrivateSetter + { + get + { + return Configuration.CollectionSettersMode == CollectionSettersMode.Private + && (IsCollection || IsArray || (IsList && IsAttribute)); + } + } + private CodeTypeReference TypeReference { get @@ -825,9 +834,9 @@ public void AddInterfaceMembersTo(CodeTypeDeclaration typeDeclaration) { CodeTypeMember member; - var isArray = IsArray; var propertyType = PropertyType; var isNullableValueType = IsNullableValueType; + var isPrivateSetter = IsPrivateSetter; var typeReference = TypeReference; if (isNullableValueType && Configuration.GenerateNullables) @@ -842,7 +851,7 @@ public void AddInterfaceMembersTo(CodeTypeDeclaration typeDeclaration) Name = Name, Type = typeReference, HasGet = true, - HasSet = !IsCollection && !isArray + HasSet = !isPrivateSetter }; if (DefaultValue != null && IsNullable) @@ -872,6 +881,7 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi var propertyType = PropertyType; var isNullableValueType = IsNullableValueType; var isNullableReferenceType = IsNullableReferenceType; + var isPrivateSetter = IsPrivateSetter; var typeReference = TypeReference; var requiresBackingField = withDataBinding || DefaultValue != null || IsCollection || isArray; @@ -935,8 +945,6 @@ public void AddMembersTo(CodeTypeDeclaration typeDeclaration, bool withDataBindi else member = new CodeMemberField(typeReference, propertyName); - var isPrivateSetter = (IsCollection || isArray || (IsList && IsAttribute)) && Configuration.CollectionSettersMode == CollectionSettersMode.Private; - if (requiresBackingField) { member.Name += GetAccessors(member.Name, backingField.Name, From 4fc5714db690c96ee539779703770523ee063f86 Mon Sep 17 00:00:00 2001 From: jmatss Date: Tue, 17 May 2022 22:49:31 +0200 Subject: [PATCH 5/5] Add unit tests for invalid interface generated --- XmlSchemaClassGenerator.Tests/XmlTests.cs | 86 +++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index 43162982..0216e8d5 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -2578,5 +2578,91 @@ public void TestArrayItemAttribute() var optionList = applicationType.GetProperty("OptionList"); Assert.Equal("Test_Generation_Namespace.T_OptionList", optionList.PropertyType.FullName); } + + [Fact] + public void CollectionSetterInAttributeGroupInterfaceIsPrivateIfCollectionSetterModeIsPrivate() + { + const string xsd = @" + + + + + + + + + + + + + + +"; + + var generator = new Generator + { + NamespaceProvider = new NamespaceProvider + { + GenerateNamespace = key => "Test", + }, + GenerateInterfaces = true, + CollectionSettersMode = CollectionSettersMode.Private + }; + var contents = ConvertXml(nameof(CollectionSetterInAttributeGroupInterfaceIsPrivateIfCollectionSetterModeIsPrivate), xsd, generator).ToArray(); + var assembly = Compiler.Compile(nameof(CollectionSetterInAttributeGroupInterfaceIsPrivateIfCollectionSetterModeIsPrivate), contents); + + var interfaceProperty = assembly.GetType("Test.IAttrGroup")?.GetProperty("Attr"); + var implementerProperty = assembly.GetType("Test.Element")?.GetProperty("Attr"); + Assert.NotNull(interfaceProperty); + Assert.NotNull(implementerProperty); + + var interfaceHasPublicSetter = interfaceProperty.GetSetMethod() != null; + var implementerHasPublicSetter = implementerProperty.GetSetMethod() != null; + Assert.False(interfaceHasPublicSetter); + Assert.False(implementerHasPublicSetter); + } + + [Fact] + public void CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic() + { + const string xsd = @" + + + + + + + + + + + + + + +"; + + var generator = new Generator + { + NamespaceProvider = new NamespaceProvider + { + GenerateNamespace = key => "Test", + }, + GenerateInterfaces = true, + CollectionSettersMode = CollectionSettersMode.Public + }; + var contents = ConvertXml(nameof(CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic), xsd, generator).ToArray(); + var assembly = Compiler.Compile(nameof(CollectionSetterInAttributeGroupInterfaceIsPublicIfCollectionSetterModeIsPublic), contents); + + var interfaceProperty = assembly.GetType("Test.IAttrGroup")?.GetProperty("Attr"); + var implementerProperty = assembly.GetType("Test.Element")?.GetProperty("Attr"); + Assert.NotNull(interfaceProperty); + Assert.NotNull(implementerProperty); + + var interfaceHasPublicSetter = interfaceProperty.GetSetMethod() != null; + var implementerHasPublicSetter = implementerProperty.GetSetMethod() != null; + Assert.True(interfaceHasPublicSetter); + Assert.True(implementerHasPublicSetter); + } } }