From 4b89ec3c23c29b826d0e181c21bde301a45db106 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Mon, 4 Apr 2022 17:55:19 +0200 Subject: [PATCH] Do not generate properties with duplicate XmlSchemaNames (see #315) --- XmlSchemaClassGenerator/TypeModel.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 117e3fae..3bac6eef 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -454,18 +454,19 @@ public override CodeTypeDeclaration Generate() keyProperty.IsKey = true; } - foreach (var property in Properties.GroupBy(x => x.Name)) + foreach (var property in Properties.GroupBy(x => x.Name).Select(g => g.Select((p, i) => (Property: p, Index: i)).ToList())) { - var propertyIndex = 1; - - foreach (var p in property) - { - if (propertyIndex > 1) + foreach (var p in property) + { + if (p.Index > 0) { - p.Name += $"_{propertyIndex}"; + p.Property.Name += $"_{p.Index + 1}"; + + if (property.Any(q => p.Property.XmlSchemaName == q.Property.XmlSchemaName && q.Index < p.Index)) + continue; } - p.AddMembersTo(classDeclaration, Configuration.EnableDataBinding); - propertyIndex++; + + p.Property.AddMembersTo(classDeclaration, Configuration.EnableDataBinding); } }