StoryTeller.Persistence.JsonNode.ForEachAttribute C# (CSharp) Method

ForEachAttribute() public method

public ForEachAttribute ( string>.Action action ) : void
action string>.Action
return void
        public void ForEachAttribute(Action<string, string> action)
        {
            foreach (var pair in _object)
            {
                if (pair.Key.StartsWith("x_") || pair.Key == CHILDREN) continue;

                action(pair.Key, pair.Value.Value<string>());
            }
        }

Usage Example

Example #1
0
        public void for_each_attribute()
        {
            var cache = new Cache<string, string>
            {
                OnMissing = key =>
                {
                    Assert.Fail(key + " does not exist");
                    return null;
                }
            };

            var node = new JsonNode("Test");
            node.InnerText = "something";

            node["a"] = "1";
            node["b"] = "2";
            node["c"] = "3";

            node.ForEachAttribute((key, value) => cache[key] = value);

            cache.Count.ShouldEqual(3);
            cache["a"].ShouldEqual("1");
            cache["b"].ShouldEqual("2");
            cache["c"].ShouldEqual("3");
        }