Exemplo n.º 1
0
        public RemovrCompositeSpec(string rawKey, JObject spec) :
            base(rawKey)
        {
            var all = new List <RemovrSpec>();

            foreach (var kv in spec)
            {
                string[] keyStrings = kv.Key.Split('|');
                foreach (string keyString in keyStrings)
                {
                    RemovrSpec childSpec;
                    if (kv.Value is JObject dic)
                    {
                        childSpec = new RemovrCompositeSpec(keyString, dic);
                    }
                    else if (kv.Value.Type == JTokenType.String && String.IsNullOrWhiteSpace(kv.Value.ToString()))
                    {
                        childSpec = new RemovrLeafSpec(keyString);
                    }
                    else
                    {
                        throw new SpecException("Invalid Removr spec RHS. Should be an empty string or Map");
                    }
                    all.Add(childSpec);
                }
            }
            _allChildNodes = all.AsReadOnly();
        }
Exemplo n.º 2
0
        public Removr(object spec)
        {
            if (spec == null)
            {
                throw new SpecException("Removr expected a spec of Map type, got 'null'.");
            }
            if (!(spec is JObject dic))
            {
                throw new SpecException("Removr expected a spec of Map type, got " + spec.GetType().Name);
            }

            _rootSpec = new RemovrCompositeSpec(ROOT_KEY, dic);
        }