EnumerateNodesOf() public method

Enumerates the key-value pairs in a mapping node
public EnumerateNodesOf ( YamlMappingNode mapping ) : YamlNode>>.IEnumerable
mapping YamlMappingNode Mapping node to be enumerated
return YamlNode>>.IEnumerable
コード例 #1
0
        /// <summary>
        /// Applies a parameter definition to the given parameters model.
        ///
        /// <para>This only has to be overridden to provide a custom parameter parsing logic. Otherwise
        /// just override <see cref="YamlProjectParametersLoaderBase{TParamType}.GetActions"/></para>
        /// </summary>
        /// <param name="target">Target model object to be filled</param>
        /// <param name="name">Option name</param>
        /// <param name="value">Option value to be parsed</param>
        /// <param name="parser">Parser to be used</param>
        protected override void TryAddParameter(ReferenceAliases target, string name, YamlNode value, YamlParser parser)
        {
            var references = new HashSet <Reference>();

            var seq = value as YamlSequenceNode;

            if (seq != null)
            {
                foreach (var referenceNode in parser.EnumerateNodesOf(seq))
                {
                    foreach (var reference in referenceLoader.LoadReference(referenceNode))
                    {
                        references.Add(reference);
                    }
                }
            }
            else
            {
                foreach (var reference in referenceLoader.LoadReference(value))
                {
                    references.Add(reference);
                }
            }

            target.Add(name, references);
        }
コード例 #2
0
        public virtual IProjectParameters Load(Suite suite, string name, YamlNode value, YamlParser parser)
        {
            this.suite = suite;

            var result  = CreateNewParameters(suite);
            var mapping = value as YamlMappingNode;

            if (mapping != null)
            {
                foreach (var pair in parser.EnumerateNodesOf(mapping))
                {
                    var scalarKey = pair.Key as YamlScalarNode;
                    if (scalarKey != null)
                    {
                        TryAddParameter(result, scalarKey.Value, pair.Value, parser);
                    }
                }
            }
            else
            {
                var hints = new List <string>();

                if (value is YamlSequenceNode)
                {
                    hints.Add("Remove the `-` characters to make it a mapping instead of sequence");
                    output.Warning(String.Format("{0} block (line {1}) is not a mapping node", BlockName, value != null ? value.Start.Line.ToString(CultureInfo.InvariantCulture) : "?"), hints.ToArray());
                }
            }

            return(result);
        }
コード例 #3
0
ファイル: YamlModelLoaderBase.cs プロジェクト: zvrana/bari
        private void LoadParameters(Suite suite, IProjectParametersHolder target, YamlNode node)
        {
            var mapping = node as YamlMappingNode;

            if (mapping != null)
            {
                foreach (var pair in parser.EnumerateNodesOf(mapping))
                {
                    if (new YamlScalarNode("postprocessors").Equals(pair.Key) &&
                        pair.Value is YamlMappingNode)
                    {
                        // skipping
                    }
                    else
                    {
                        TryAddParameters(suite, target, pair.Key, pair.Value);
                    }
                }
            }
        }
コード例 #4
0
        protected string[] ParseStringArray(YamlParser parser, YamlNode value)
        {
            var seq = value as YamlSequenceNode;

            if (seq != null)
            {
                return(parser.EnumerateNodesOf(seq).OfType <YamlScalarNode>().Select(childValue => childValue.Value).ToArray());
            }
            else
            {
                return(new string[0]);
            }
        }
コード例 #5
0
        private IEnumerable <Uri> LoadPlugins(YamlNode rootNode)
        {
            var result = new List <Uri>();

            var      rootMapping = (YamlMappingNode)rootNode;
            YamlNode node;

            if (rootMapping.Children.TryGetValue(new YamlScalarNode("plugins"), out node))
            {
                var pluginsNode = node as YamlSequenceNode;
                if (pluginsNode != null)
                {
                    foreach (var item in parser.EnumerateNodesOf(pluginsNode))
                    {
                        var scalar = item as YamlScalarNode;
                        if (scalar != null)
                        {
                            try
                            {
                                result.Add(new Uri(scalar.Value));
                            }
                            catch (UriFormatException)
                            {
                                output.Warning(String.Format("Invalid plugin reference: {0}", scalar.Value));
                            }
                        }
                        else
                        {
                            output.Warning("Invalid child item ");
                        }
                    }
                }
            }

            return(result);
        }
コード例 #6
0
        protected bool ParseBool(YamlParser parser, YamlNode value)
        {
            var seq = value as YamlSequenceNode;

            if (seq != null)
            {
                var values = parser.EnumerateNodesOf(seq).OfType <YamlScalarNode>().Select(childValue => ParseBool(parser, childValue)).ToList();
                if (values.Any())
                {
                    return(values.First());
                }

                return(false);
            }

            var scalarValue = (YamlScalarNode)value;

            return("true".Equals(scalarValue.Value, StringComparison.InvariantCultureIgnoreCase) ||
                   "yes".Equals(scalarValue.Value, StringComparison.InvariantCultureIgnoreCase));
        }
コード例 #7
0
        public virtual IProjectParameters Load(Suite suite, string name, YamlNode value, YamlParser parser)
        {
            this.suite = suite;

            var result  = CreateNewParameters(suite);
            var mapping = value as YamlMappingNode;

            if (mapping != null)
            {
                foreach (var pair in parser.EnumerateNodesOf(mapping))
                {
                    var scalarKey = pair.Key as YamlScalarNode;
                    if (scalarKey != null)
                    {
                        TryAddParameter(result, scalarKey.Value, pair.Value, parser);
                    }
                }
            }

            return(result);
        }