Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request/Question: Create List<T> instead of class for elements with a single sequence. #334

Open
las-nsc opened this issue Jun 6, 2022 · 1 comment

Comments

@las-nsc
Copy link
Contributor

las-nsc commented Jun 6, 2022

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.

@mganss
Copy link
Owner

mganss commented Jun 7, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants