Skip to content

Unions default to string serialization #397

@jzabroski

Description

@jzabroski

The following XSD generates a string representation for Date/DateTime:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0.48448">
  <xs:simpleType name="SnapshotDate">
    <xs:restriction base="xs:date" />
  </xs:simpleType>
  <xs:simpleType name="SnapshotDateTime">
    <xs:restriction base="xs:dateTime" />
  </xs:simpleType>

  <xs:element name="Snapshot">
    <xs:complexType>
      <xs:attribute name="Date" use="required">
        <xs:simpleType>
          <xs:union memberTypes="SnapshotDate SnapshotDateTime" />
        </xs:simpleType>
      </xs:attribute>
    </xs:complexType>
  </xs:element>
</xs:schema>

It would be ideal if this used either the OneOf nuget package to handle the union directly, or did clever inference to infer date and dateTime are both the same .NET data type (except if on .NET 6 and DateOnly is supported). For backwards compatibility reasons, I'd rather the generator not use DateOnly, as I still rely on your tool for .NET Framework apps until for at least another 6-12 months.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions