diff --git a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj
index 28c87204..73ecadbc 100644
--- a/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj
+++ b/XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj
@@ -128,6 +128,12 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs
index 216ff11d..b81f706a 100644
--- a/XmlSchemaClassGenerator.Tests/XmlTests.cs
+++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs
@@ -378,6 +378,16 @@ public void EditorBrowsableAttributeRespectsCodeTypeReferenceOptions(CodeTypeRef
}
+ [Theory]
+ [InlineData(@"xml/sameattributenames.xsd", @"xml/sameattributenames_import.xsd")]
+ public void CollidingAttributeAndPropertyNamesCanBeResolved(params string[] files)
+ {
+ // Compilation would previously throw due to duplicate type name within type
+ var assembly = Compiler.GenerateFiles("AttributesWithSameName", files);
+
+ Assert.NotNull(assembly);
+ }
+
[Fact]
public void ComplexTypeWithAttributeGroupExtension()
{
diff --git a/XmlSchemaClassGenerator.Tests/xml/sameattributenames.xsd b/XmlSchemaClassGenerator.Tests/xml/sameattributenames.xsd
new file mode 100644
index 00000000..dda80a3c
--- /dev/null
+++ b/XmlSchemaClassGenerator.Tests/xml/sameattributenames.xsd
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/XmlSchemaClassGenerator.Tests/xml/sameattributenames_import.xsd b/XmlSchemaClassGenerator.Tests/xml/sameattributenames_import.xsd
new file mode 100644
index 00000000..0ff0aa76
--- /dev/null
+++ b/XmlSchemaClassGenerator.Tests/xml/sameattributenames_import.xsd
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs
index a71fa388..a65aab14 100644
--- a/XmlSchemaClassGenerator/TypeModel.cs
+++ b/XmlSchemaClassGenerator/TypeModel.cs
@@ -383,10 +383,21 @@ public override CodeTypeDeclaration Generate()
keyProperty.IsKey = true;
}
- foreach (var property in Properties)
- property.AddMembersTo(classDeclaration, Configuration.EnableDataBinding);
-
- if (IsMixed && (BaseClass == null || (BaseClass is ClassModel && !AllBaseClasses.Any(b => b.IsMixed))))
+ foreach (var property in Properties.GroupBy(x => x.Name))
+ {
+ var propertyIndex = 0;
+ foreach (var p in property)
+ {
+ if (propertyIndex > 0)
+ {
+ p.Name += $"_{propertyIndex}";
+ }
+ p.AddMembersTo(classDeclaration, Configuration.EnableDataBinding);
+ propertyIndex++;
+ }
+ }
+
+ if (IsMixed && (BaseClass == null || (BaseClass is ClassModel && !AllBaseClasses.Any(b => b.IsMixed))))
{
var text = new CodeMemberField(typeof(string), "Text");
// hack to generate automatic property