internal CustomControlEntry(ComplexControlEntryDefinition entry)
        {
            if (entry.appliesTo != null)
            {
                SelectedBy = EntrySelectedBy.Get(entry.appliesTo.referenceList);
            }

            CustomItems = new List <CustomItemBase>();
            foreach (var tok in entry.itemDefinition.formatTokenList)
            {
                CustomItems.Add(CustomItemBase.Create(tok));
            }
        }
        internal static CustomItemBase Create(FormatToken token)
        {
            if (token is NewLineToken)
            {
                return(new CustomItemNewline());
            }

            var textToken = token as TextToken;

            if (textToken != null)
            {
                return(new CustomItemText {
                    Text = textToken.text
                });
            }

            var frameToken = token as FrameToken;

            if (frameToken != null)
            {
                var frame = new CustomItemFrame
                {
                    RightIndent = (uint)frameToken.frameInfoDefinition.rightIndentation,
                    LeftIndent  = (uint)frameToken.frameInfoDefinition.leftIndentation
                };
                var firstLine = frameToken.frameInfoDefinition.firstLine;
                if (firstLine > 0)
                {
                    frame.FirstLineIndent = (uint)firstLine;
                }
                else if (firstLine < 0)
                {
                    frame.FirstLineHanging = (uint)-firstLine;
                }
                foreach (var frameItemToken in frameToken.itemDefinition.formatTokenList)
                {
                    frame.CustomItems.Add(CustomItemBase.Create(frameItemToken));
                }
                return(frame);
            }

            var cpt = token as CompoundPropertyToken;

            if (cpt != null)
            {
                var cie = new CustomItemExpression {
                    EnumerateCollection = cpt.enumerateCollection
                };

                if (cpt.conditionToken != null)
                {
                    cie.ItemSelectionCondition = new DisplayEntry(cpt.conditionToken);
                }

                if (cpt.expression.expressionValue != null)
                {
                    cie.Expression = new DisplayEntry(cpt.expression);
                }

                if (cpt.control != null)
                {
                    cie.CustomControl = new CustomControl((ComplexControlBody)cpt.control, null);
                }

                return(cie);
            }

            var fpt = token as FieldPropertyToken;

            if (fpt != null)
            {
            }

            Diagnostics.Assert(false, "Unexpected formatting token kind");

            return(null);
        }