Esempio n. 1
0
        static public Either <Errors.FormatError, Rule> DeserializeV1(Format.Schema.RuleV1 rule)
        {
            List <Predicate> body = new List <Predicate>();

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

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

            foreach (Format.Schema.ExpressionV1 expression in rule.Expressions)
            {
                Either <Errors.FormatError, Expression> result = Expression.DeserializeV1(expression);
                if (result.IsLeft)
                {
                    return(result.Left);
                }
                else
                {
                    expressions.Add(result.Right);
                }
            }

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

            if (res.IsLeft)
            {
                return(res.Left);
            }
            else
            {
                return(new Rule(res.Right, body, expressions));
            }
        }
Esempio n. 2
0
        public Format.Schema.RuleV1 Serialize()
        {
            Format.Schema.RuleV1 b = new Format.Schema.RuleV1()
            {
                Head = this.Head.Serialize()
            };

            for (int i = 0; i < this.Body.Count; i++)
            {
                b.Body.Add(this.Body[i].Serialize());
            }

            for (int i = 0; i < this.Expressions.Count; i++)
            {
                b.Expressions.Add(this.Expressions[i].Serialize());
            }

            return(b);
        }