private static int CompareChildEntries(ChildEntry x, ChildEntry y)
        {
            if (x.ChildType == ChildType.Element &&
                y.ChildType == ChildType.Element ||
                x.ChildType == ChildType.ElementExtension &&
                y.ChildType == ChildType.ElementExtension)
            {
                var xElement = (XmlSchemaElement)x.Particle;
                var yElement = (XmlSchemaElement)y.Particle;
                return xElement.QualifiedName.Name.CompareTo(yElement.QualifiedName.Name);
            }

            if (x.ChildType == y.ChildType)
                return 0;

            if (x.ChildType == ChildType.Any)
                return 1;

            if (y.ChildType == ChildType.Any)
                return -1;

            if (x.ChildType != ChildType.Element)
                return -1;

            if (y.ChildType != ChildType.Element)
                return 1;

            return 0;
        }
Example #2
0
        private static bool CanInline(ChildType parentChildType, ChildEntry child)
        {
            if (child.ChildType == parentChildType)
            {
                if (child.ChildType == ChildType.Sequence ||
                    child.ChildType == ChildType.Choice)
                {
                    if (child.MinOccurs == 1 && child.MaxOccurs == 1)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #3
0
        private ChildEntry AddLeaf(ChildType childType, XmlSchemaObject parent, XmlSchemaParticle particle)
        {
            if (_childEntryStack.Count == 0)
            {
                var root = new List <ChildEntry>();
                _childEntryStack.Push(root);
            }

            var childEntry = new ChildEntry
            {
                ChildType = childType,
                MinOccurs = particle == null ? 1 : particle.MinOccurs,
                MaxOccurs = particle == null ? 1 : particle.MaxOccurs,
                Particle  = particle,
                Parent    = parent
            };

            _childEntryStack.Peek().Add(childEntry);
            return(childEntry);
        }
Example #4
0
        private static ChildEntry InlineParticles(ChildEntry parent)
        {
            var particleAllowsInlining = parent.ChildType == ChildType.All ||
                                         parent.ChildType == ChildType.Choice ||
                                         parent.ChildType == ChildType.Sequence;

            if (particleAllowsInlining && parent.Children.Count == 1)
            {
                var child = parent.Children[0];
                child.MinOccurs = parent.MinOccurs * child.MinOccurs;
                child.MaxOccurs = (parent.MaxOccurs == Decimal.MaxValue ||
                                   child.MaxOccurs == Decimal.MaxValue)
                                    ? Decimal.MaxValue
                                    : parent.MaxOccurs * child.MaxOccurs;
                return(child);
            }

            var newChildren = new List <ChildEntry>();

            foreach (var child in parent.Children)
            {
                var replacedChild = InlineParticles(child);

                if (CanInline(parent.ChildType, replacedChild))
                {
                    newChildren.AddRange(replacedChild.Children);
                }
                else
                {
                    newChildren.Add(replacedChild);
                }
            }

            parent.Children.Clear();
            parent.Children.AddRange(newChildren);
            return(parent);
        }
        private static void WriteOccurrence(this MamlWriter writer, ChildEntry entry)
        {
            if (entry.MinOccurs == 1 && entry.MaxOccurs == 1)
                return;

            if (entry.MaxOccurs == decimal.MaxValue)
                writer.WriteString("[{0}, *]", entry.MinOccurs);
            else
                writer.WriteString("[{0}, {1}]", entry.MinOccurs, entry.MaxOccurs);
        }
 private static void WriteName(this MamlWriter writer, ChildEntry entry, TopicManager topicManager)
 {
     switch (entry.ChildType)
     {
         case ChildType.Element:
         case ChildType.ElementExtension:
             var element = (XmlSchemaElement)entry.Particle;
             var isExtension = (entry.ChildType == ChildType.ElementExtension);
             writer.WriteElementLink(topicManager, element, isExtension);
             break;
         case ChildType.Any:
             writer.WriteHtmlArtItemWithText(ArtItem.AnyElement, "Any");
             break;
         case ChildType.All:
             writer.WriteHtmlArtItemWithText(ArtItem.All, "All");
             break;
         case ChildType.Choice:
             writer.WriteHtmlArtItemWithText(ArtItem.Choice, "Choice");
             break;
         case ChildType.Sequence:
             writer.WriteHtmlArtItemWithText(ArtItem.Sequence, "Sequence");
             break;
         default:
             throw ExceptionBuilder.UnhandledCaseLabel(entry.ChildType);
     }
 }
 private static void WriteDescription(this MamlWriter writer, ChildEntry entry, Context context)
 {
     if (entry.Particle != null)
         writer.WriteSummaryForObject(context, entry.Particle);
 }
Example #8
0
        private ChildEntry AddLeaf(ChildType childType, XmlSchemaObject parent, XmlSchemaParticle particle)
        {
            if (_childEntryStack.Count == 0)
            {
                var root = new List<ChildEntry>();
                _childEntryStack.Push(root);
            }

            var childEntry = new ChildEntry
                             {
                                 ChildType = childType,
                                 MinOccurs = particle == null ? 1 : particle.MinOccurs,
                                 MaxOccurs = particle == null ? 1 : particle.MaxOccurs,
                                 Particle = particle,
                                 Parent = parent
                             };
            _childEntryStack.Peek().Add(childEntry);
            return childEntry;
        }
Example #9
0
        private static ChildEntry InlineParticles(ChildEntry parent)
        {
            var particleAllowsInlining = parent.ChildType == ChildType.All ||
                                         parent.ChildType == ChildType.Choice ||
                                         parent.ChildType == ChildType.Sequence;

            if (particleAllowsInlining && parent.Children.Count == 1)
            {
                var child = parent.Children[0];
                child.MinOccurs = parent.MinOccurs * child.MinOccurs;
                child.MaxOccurs = (parent.MaxOccurs == Decimal.MaxValue ||
                                   child.MaxOccurs == Decimal.MaxValue)
                                    ? Decimal.MaxValue
                                    : parent.MaxOccurs * child.MaxOccurs;
                return child;
            }

            var newChildren = new List<ChildEntry>();
            foreach (var child in parent.Children)
            {
                var replacedChild = InlineParticles(child);

                if (CanInline(parent.ChildType, replacedChild))
                    newChildren.AddRange(replacedChild.Children);
                else
                    newChildren.Add(replacedChild);
            }

            parent.Children.Clear();
            parent.Children.AddRange(newChildren);
            return parent;
        }
Example #10
0
        private static bool CanInline(ChildType parentChildType, ChildEntry child)
        {
            if (child.ChildType == parentChildType)
            {
                if (child.ChildType == ChildType.Sequence ||
                    child.ChildType == ChildType.Choice)
                {
                    if (child.MinOccurs == 1 && child.MaxOccurs == 1)
                        return true;
                }
            }

            return false;
        }