Esempio n. 1
0
        private IConstraint ConvertJsonToConstraint(JObject jObject)
        {
            if (jObject["and"] != null)
            {
                var andConstraint = new AndConstraint();
                foreach (var item in jObject["and"])
                {
                    andConstraint.Add(ConvertJsonToConstraint((item as JObject)));
                }

                return(andConstraint);
            }
            if (jObject["or"] != null)
            {
                var orConstraint = new OrConstraint();
                foreach (var item in jObject["or"])
                {
                    orConstraint.Add(ConvertJsonToConstraint((item as JObject)));
                }

                return(orConstraint);
            }
            if (jObject["equals"] != null)
            {
                var equalsConstraint = new EqualsConstraint();

                equalsConstraint.Property     = jObject["equals"][0]["doc"]?.ToString();
                equalsConstraint.ValueToEqual = jObject["equals"][1]?.ToString();

                return(equalsConstraint);
            }
            if (jObject["in"] != null)
            {
                var inConstraint = new InConstraint();

                inConstraint.Property      = jObject["in"][0]["doc"]?.ToString();
                inConstraint.ValuesToEqual = jObject["in"][1]?.ToObject <string[]>();

                return(inConstraint);
            }
            if (jObject["paths"] != null)
            {
                var pathsConstraint = new PathConstraint();

                pathsConstraint.Fields = jObject["paths"][0]["doc"]?.ToString();

                return(pathsConstraint);
            }
            if (jObject["not"] != null)
            {
                var notConstraint = new NotConstraint();

                notConstraint.ConstraintToInvert = ConvertJsonToConstraint(jObject["not"] as JObject);

                return(notConstraint);
            }

            return(null);
        }