Skip to content

Commit 4b89ec3

Browse files
author
Michael Ganss
committed
Do not generate properties with duplicate XmlSchemaNames (see #315)
1 parent 7576f89 commit 4b89ec3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

XmlSchemaClassGenerator/TypeModel.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -454,18 +454,19 @@ public override CodeTypeDeclaration Generate()
454454
keyProperty.IsKey = true;
455455
}
456456

457-
foreach (var property in Properties.GroupBy(x => x.Name))
457+
foreach (var property in Properties.GroupBy(x => x.Name).Select(g => g.Select((p, i) => (Property: p, Index: i)).ToList()))
458458
{
459-
var propertyIndex = 1;
460-
461-
foreach (var p in property)
462-
{
463-
if (propertyIndex > 1)
459+
foreach (var p in property)
460+
{
461+
if (p.Index > 0)
464462
{
465-
p.Name += $"_{propertyIndex}";
463+
p.Property.Name += $"_{p.Index + 1}";
464+
465+
if (property.Any(q => p.Property.XmlSchemaName == q.Property.XmlSchemaName && q.Index < p.Index))
466+
continue;
466467
}
467-
p.AddMembersTo(classDeclaration, Configuration.EnableDataBinding);
468-
propertyIndex++;
468+
469+
p.Property.AddMembersTo(classDeclaration, Configuration.EnableDataBinding);
469470
}
470471
}
471472

0 commit comments

Comments
 (0)