XmlSchemaClassGenerator
XmlSchemaClassGenerator copied to clipboard
Feature Request/Question: Create `List<T>` instead of `class` for elements with a single sequence.
Forgive me if this is already possible somehow, but when there is an element/class with only a single sequence within it, could it just use a List<T>
where the name of the variable is the name of the element? This would solve several cases where the collection name should be plural too.
<Foo>
<Bars>
<Bar/>
<Bar/>
<Bar/>
<Bars>
</Foo>
currently makes:
public class Foo {
public Bars Bars { get; } = new();
}
public class Bars {
public List<Bar> Bar { get; } = new();
}
public class Bar { }
// Access
Foo foo = new();
foreach (var bar in foo.Bars.Bar) { }
But could be:
public class Foo {
public List<Bar> Bars { get; } = new();
}
public class Bar { }
// Access
Foo foo = new();
foreach (var bar in foo.Bars) { }
Maybe this is already possible, either with a flag or by changing the XSD somehow, or maybe it wouldn't work with the XmlSerializer
, but it seems like it should be this way.
This should be possible by using the --useArrayItemAttribute
option which is true by default. If this doesn't work for you, can you share an example xsd?