示例#1
0
        static public Either <Errors.FormatError, Rule> DeserializeV0(Format.Schema.RuleV0 rule)
        {
            List <Predicate> body = new List <Predicate>();

            foreach (Format.Schema.PredicateV0 predicate in rule.Body)
            {
                Either <Errors.FormatError, Predicate> result = Predicate.DeserializeV0(predicate);
                if (result.IsLeft)
                {
                    return(result.Left);
                }
                else
                {
                    body.Add(result.Right);
                }
            }

            List <Expression> expressions = new List <Expression>();

            foreach (Format.Schema.ConstraintV0 constraint in rule.Constraints)
            {
                Either <Errors.FormatError, Expression> result = Constraint.DeserializeV0(constraint);
                if (result.IsLeft)
                {
                    return(result.Left);
                }
                else
                {
                    expressions.Add(result.Right);
                }
            }

            Either <Errors.FormatError, Predicate> res = Predicate.DeserializeV0(rule.Head);

            if (res.IsLeft)
            {
                return(res.Left);
            }
            else
            {
                return(new Rule(res.Right, body, expressions));
            }
        }