mamift / LinqToXsdCore

LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ for the code generator CLI tool).
Microsoft Public License
43 stars 15 forks source link

Enum generation not working #13

Closed justinoverton closed 4 years ago

justinoverton commented 4 years ago

I noticed that enum generation is not working when the restriction is an anonymous type of an attribute.

The atom.xsd will show the issue because the textType's type attribute is generated as a string instead of an enum.

Part of it is within XsdToTypesConverter.cs BuildProperty for attribute where name of the type is set to he name of the attribute

            XmlSchemaSimpleType schemaType = attribute.AttributeSchemaType;
            var qName = schemaType.QualifiedName;
            if (qName.IsEmpty) {
                qName = attribute.QualifiedName;

Then later in TypesToCodeDom.cs ProcessProperties enum is only generated if it is an anonymous type:

                    var typeRef = propertyInfo.TypeReference;
                    if (typeRef.IsEnum && string.IsNullOrEmpty(typeRef.Name))
                    {
                        typeRef.Name = $"{propertyInfo.PropertyName}s";
                        CreateNestedEnumType(typeRef);
                    }
mamift commented 4 years ago

Yes thanks for reporting this; this was a very recent change implemented in the last month or so. I just haven't been able to get around to addressing it yet due to the current health situation.

mamift commented 4 years ago

Oh hey, I just realised the nuget package isn't on the README. The last stable release (which doesn't yet include enum generation), is on Nuget: https://www.nuget.org/packages/LinqToXsdCore

mamift commented 4 years ago

Hello, I believe I have fixed this particular issue; there is one more outstanding bug with enum generation, but for this one I believe it is fixed in https://github.com/mamift/LinqToXsdCore/commit/992b7393a0e7f5e6106eb46e326c817f97ca7e33