XmlSchemaClassGenerator icon indicating copy to clipboard operation
XmlSchemaClassGenerator copied to clipboard

Interaction of --collectionSettersMode with --nullableReferenceAttributes

Open strigefleur opened this issue 2 months ago • 10 comments

Using NR arg (--nullableReferenceAttributes) we can get collection decorated with attributes like that

  [XmlArray("ErrorList")]
  [XmlArrayItem("Error", Namespace = "http://ns-here")]
  public Collection<ErrorDataType> ErrorList
  {
    [return: MaybeNull] get => this._errorList;
    [param: AllowNull] init => this._errorList = value;
  }

though collection setters with backing field (--collectionSettersMode=Init) let init the collection

public ErrorListType()
{
    this._errorList = new Collection<ErrorDataType>();
}

Now there's a conflict, since removing the backing field entirely removes all of collection initializers - both nullable and not nullable, but letting it stay leads to erroneously initialized empty collections that supposed to be null.

Expected to have empty collection when empty tag presents (<ErrorList/>) but null collection when no tag presents.

Am I missing some obvious arg combination?

strigefleur avatar Oct 22 '25 20:10 strigefleur