Example #1
0
        private void TryParseContentItems(YNode node, ref Dictionary <string, string> dict, string prefix = null)
        {
            switch (node)
            {
            case YKeyValuePair keyValuePair:
                string key = null;
                try
                {
                    key = (string)keyValuePair.Key;
                }
                catch (System.Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                key = string.IsNullOrEmpty(prefix) ? key : string.Concat(prefix, Separator, key);
                if (keyValuePair.Value is YScalar valueScalar)
                {
                    dict[key] = valueScalar.Value;
                }
                else
                {
                    this.TryParseContentItems(keyValuePair.Value, ref dict, key);
                }

                break;

            case YSequence sequence:
                // TODO: need suppoer Enum fields
                foreach (var sequenceChild in sequence.Children)
                {
                    if (sequenceChild is YScalar yScalar)
                    {
                        dict[string.Concat(prefix, Separator, yScalar.Value)] = yScalar.Value;
                    }
                }

                break;

            case YMapping mapping:
                foreach (var mapItem in mapping)
                {
                    this.TryParseContentItems(mapItem, ref dict, prefix);
                }

                break;

            case IEnumerable <YNode> collection:
                foreach (var colItem in collection)
                {
                    this.TryParseContentItems(colItem, ref dict, prefix);
                }

                break;
            }
        }
 protected internal abstract void RemoveChild(YNode node);
 protected internal abstract YNode GetNextNode(YNode node);
 protected internal abstract YNode GetPreviousNode(YNode node);
Example #5
0
 // https://gist.github.com/bowsersenior/979804
 private YAnchor(YNode value)
     : base(YNodeStyle.Block)
 {
     this.Value = value;
 }
Example #6
0
 protected internal override YNode GetNextNode(YNode node)
 {
     return(node == this.LastNode ? null :
            node is YKeyValuePair pair ? this.Children[this.Children.IndexOf(pair) + 1] : null);
 }
Example #7
0
 protected internal override YNode GetPreviousNode(YNode node)
 {
     return(node == this.FirstNode ? null :
            node is YKeyValuePair pair ? this.Children[this.Children.IndexOf(pair) - 1] : null);
 }