diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index 0c377936..4a79cda9 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -482,7 +482,7 @@ public void TestWfs() { OutputWriter = output, EmitOrder = true, - GenerateInterfaces = false + GenerateInterfaces = true }); TestSamples("wfs", WfsPattern); } @@ -992,7 +992,7 @@ public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions(CodeTypeRef { CodeTypeReferenceOptions = codeTypeReferenceOptions, GenerateNullables = true, - GenerateInterfaces = false, + GenerateInterfaces = true, NamespaceProvider = new NamespaceProvider { GenerateNamespace = key => "Test" diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index 6ce961b4..8abc4673 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -298,9 +298,14 @@ public static string GetUniquePropertyName(this TypeModel tm, string name) var i = 0; var n = name; var baseClasses = cls.AllBaseClasses.ToList(); + var props = cls.Properties.ToList(); - while (baseClasses.SelectMany(b => b.Properties).Any(p => p.Name == n)) + while (baseClasses.SelectMany(b => b.Properties) + .Concat(props) + .Any(p => p.Name == n)) + { n = name + (++i); + } return n; } diff --git a/XmlSchemaClassGenerator/ModelBuilder.cs b/XmlSchemaClassGenerator/ModelBuilder.cs index 51dea5db..a2c97c8d 100644 --- a/XmlSchemaClassGenerator/ModelBuilder.cs +++ b/XmlSchemaClassGenerator/ModelBuilder.cs @@ -69,6 +69,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set) if (configuration.GenerateInterfaces) { + PromoteInterfacePropertiesToCollection(); RenameInterfacePropertiesIfRenamedInDerivedClasses(); RemoveDuplicateInterfaceProperties(); } @@ -184,7 +185,8 @@ private void RenameInterfacePropertiesIfRenamedInDerivedClasses() { if (implementationClassProperty.Name != implementationClassProperty.OriginalPropertyName && implementationClassProperty.OriginalPropertyName == interfaceProperty.Name - && implementationClassProperty.XmlSchemaName == interfaceProperty.XmlSchemaName) + && implementationClassProperty.XmlSchemaName == interfaceProperty.XmlSchemaName + && implementationClassProperty.IsAttribute == interfaceProperty.IsAttribute) { RenameInterfacePropertyInBaseClasses(interfaceModel, implementationClass, interfaceProperty, implementationClassProperty.Name); interfaceProperty.Name = implementationClassProperty.Name; @@ -195,6 +197,28 @@ private void RenameInterfacePropertiesIfRenamedInDerivedClasses() } } + private void PromoteInterfacePropertiesToCollection() + { + foreach (var interfaceModel in Types.Values.OfType()) + { + foreach (var interfaceProperty in interfaceModel.Properties) + { + var derivedProperties = interfaceModel.AllDerivedReferenceTypes().SelectMany(t => t.Properties) + .Where(p => p.Name == interfaceProperty.Name || p.OriginalPropertyName == interfaceProperty.Name).ToList(); + + if (derivedProperties.Any(p => p.IsCollection)) + { + foreach (var derivedProperty in derivedProperties.Where(p => !p.IsCollection)) + { + derivedProperty.IsCollection = true; + } + + interfaceProperty.IsCollection = true; + } + } + } + } + private static void RenameInterfacePropertyInBaseClasses(InterfaceModel interfaceModel, ReferenceTypeModel implementationClass, PropertyModel interfaceProperty, string newName) { @@ -752,6 +776,7 @@ private IEnumerable CreatePropertiesForAttributes(Uri source, Typ { var attributeQualifiedName = attribute.AttributeSchemaType.QualifiedName; var attributeName = _configuration.NamingProvider.AttributeNameFromQualifiedName(attribute.QualifiedName, attribute); + var originalAttributeName = attributeName; if (attribute.Parent is XmlSchemaAttributeGroup attributeGroup && attributeGroup.QualifiedName != typeModel.XmlSchemaName @@ -795,6 +820,7 @@ private IEnumerable CreatePropertiesForAttributes(Uri source, Typ { OwningType = typeModel, Name = attributeName, + OriginalPropertyName = originalAttributeName, XmlSchemaName = attribute.QualifiedName, Type = CreateTypeModel(attribute.AttributeSchemaType, attributeQualifiedName), IsAttribute = true,