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

Enum list in attribute #365

Open
Liwoj opened this issue Dec 4, 2022 · 2 comments
Open

Enum list in attribute #365

Liwoj opened this issue Dec 4, 2022 · 2 comments

Comments

@Liwoj
Copy link

Liwoj commented Dec 4, 2022

Thanks for a great tool. I'm trying to migrate some code generation from xsd.exe and found one place where your generator fails

Following schema:

        <xs:simpleType name="FontAttributes">
		<xs:list>
			<xs:simpleType>
				<xs:restriction base="xs:string">
					<xs:enumeration value="Bold"/>
					<xs:enumeration value="Italic"/>
                                        <xs:enumeration value="Underline"/>
				</xs:restriction>                  
			</xs:simpleType>               
		</xs:list>
	</xs:simpleType>

	<xs:complexType name="DisplayProperties">
		<xs:attribute name="foregroundColor" type="xs:string" use="optional">
		</xs:attribute>
		<xs:attribute name="backgroundColor" type="xs:string" use="optional">
		</xs:attribute>
		<xs:attribute name="fontAttributes" type="FontAttributes" use="optional">
		</xs:attribute>
	</xs:complexType>

XSD correctly generates an enum FontAttributes and use it for (de)serialization of fontAttributes attribute.

    [System.FlagsAttribute()]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="cra.vub/webservices/definitions")]
    public enum FontAttributes {
        
        /// <remarks/>
        Bold = 1,
        
        /// <remarks/>
        Italic = 2,
        
        /// <remarks/>
        Underline = 4,
    }

But XmlSchemaClassGenerator generates the field as string[] FontAttributes.
Is my schema wrong or is this problem for XmlSchemaClassGenerator ?

Thanks!

@mganss
Copy link
Owner

mganss commented Dec 5, 2022

This is currently unsupported. Xsd.exe treats lists of enums as a special case where it generates an enum with FlagsAtribute and corresponding enum members that are powers of 2. This probably covers the typical use case but doesn't allow for list items to occur more than once.

It would be nice if XmlSchemaClassGenerator had this capability, too (perhaps behind a flag). Would you be interested in providing a PR?

@Liwoj
Copy link
Author

Liwoj commented Dec 10, 2022

Thanks for confirmation.

Can you label this as enhancement? As I'm pretty busy right now and the workaround is pretty easy, this has no priority. I might take a look at it again in the future (maybe when more people show interest)

Thanks again!

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

No branches or pull requests

2 participants