public override ParsingResultNode Clone()
        {
            var newItem = new SwitchResult(Label);

            newItem.Value = Value;
            foreach (var key in Cases.Keys)
            {
                newItem.Cases.Add(key, (GroupResult)Cases[key].Clone());
            }
            newItem.Else = (GroupResult)Else.Clone();

            return(newItem);
        }
Beispiel #2
0
        private void BuildResultTreeNodes(ParsingResultNodeList prnl, FieldCollectionBase confItems)
        {
            foreach (FieldElementBase item in confItems)
            {
                if (item is ConstantElement)
                {
                    var element = (ConstantElement)item;
                    prnl.Add(new ConstantResult(element));
                }
                else if (item is SwitchElement) // as switch is of field type, it must be checked before
                {
                    var element = (SwitchElement)item;
                    var sw      = new SwitchResult(element);
                    prnl.Add(sw);

                    foreach (GroupElement c in element.Cases)
                    {
                        if (c is CaseElement)
                        {
                            var caseE = (CaseElement)c;
                            var gp    = new GroupResult(caseE.Label);
                            sw.Cases.Add(caseE.When, gp);
                            BuildResultTreeNodes(gp.Children, caseE.Fields);
                        }
                        else if (c is ElseElement)
                        {
                            if (sw.Else != null)
                            {
                                throw new ParserException("Only 1 else case can be defined in a switch!");
                            }
                            var elseE = (ElseElement)c;
                            var gp    = new GroupResult(elseE.Label);
                            sw.Else = gp;
                            BuildResultTreeNodes(gp.Children, elseE.Fields);
                        }
                    }
                }
                else if (item is FieldElement)
                {
                    var element = (FieldElement)item;
                    prnl.Add(new FieldResult(element));
                }
                else if (item is LoopElement) // as loop is of type group, it must be checked before
                {
                    var element = (LoopElement)item;
                    var node    = new LoopResult(element);
                    prnl.Add(node);
                    BuildResultTreeNodes(node.Template, element.Fields);
                }
                else if (item is GroupElement)
                {
                    var element = (GroupElement)item;
                    var node    = new GroupResult(element);
                    prnl.Add(node);
                    BuildResultTreeNodes(node.Children, element.Fields);
                }
                else if (item is PartRefElement)
                {
                    var         element = (PartRefElement)item;
                    PartElement pe;
                    if (!Configuration.Parts.TryFindById(element.PartId, out pe))
                    {
                        throw new ParserException(Invariant($"Invalid partRef: unknow part id '{element.PartId}'"));
                    }
                    var node = new GroupResult(element.Label);
                    prnl.Add(node);
                    BuildResultTreeNodes(node.Children, pe.Fields);
                }
                else
                {
                    throw new ParserException(Invariant($"Unsupported field with name '{item.Label}'"));
                }
            }
        }