﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;

namespace Codge.Generator.Presentations.Xsd
{
    public static class XmlSchemaExtensions
    {
        public static bool IsEmptyType(this XmlSchemaComplexType type)
        {
            return type.ContentModel == null && type.Attributes.Count == 0 && type.ContentType.ToString() == "Empty";
        }

        public static IEnumerable<XmlSchemaEnumerationFacet> GetEnumerationFacets(this XmlSchemaSimpleType simpleType)
        {
            if (simpleType.Content != null)
            {
                var restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;
                if (restriction != null && restriction.Facets != null && restriction.Facets.Count > 0)
                {
                    foreach (var facet in restriction.Facets)
                    {
                        var item = facet as XmlSchemaEnumerationFacet;
                        if (item == null)
                            yield break;

                        yield return item;
                    }
                }
            }
            yield break;
        }

        public static bool IsEnumeration(this XmlSchemaSimpleType simpleType)
        {
            return GetEnumerationFacets(simpleType).Any();
        }
    }
}

﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Schema;

namespace Codge.Generator.Presentations.Xsd
{
    public static class XmlSchemaExtensions
    {
        public static bool IsEmptyType(this XmlSchemaComplexType type)
        {
            return type.ContentModel == null && type.Attributes.Count == 0 && type.ContentType.ToString() == "Empty";
        }

        public static IEnumerable<XmlSchemaEnumerationFacet> GetEnumerationFacets(this XmlSchemaSimpleType simpleType)
        {
            if (simpleType.Content != null)
            {
                var restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;
                if (restriction != null && restriction.Facets != null && restriction.Facets.Count > 0)
                {
                    foreach (var facet in restriction.Facets)
                    {
                        var item = facet as XmlSchemaEnumerationFacet;
                        if (item != null)
                            yield return item;
                    }
                }
            }
            yield break;
        }

        public static bool IsEnumeration(this XmlSchemaSimpleType simpleType)
        {
            return GetEnumerationFacets(simpleType).Any();
        }
    }
}

Fix for treating enum types as primitives due non-enumeration facets
Fix for treating enum types as primitives due non-enumeration facets
