Serialize and deserialize rules

Sep 28, 2016 at 1:41 PM

Thanks for the Rules Engine, it is great.

Is there a way to serialize the something like this -

FluentBuilder builder = new Fluent.FluentBuilder();
            .Setup(p => p.Age)
            .Setup(p => p.Name)
My goal is to save rules to a database and load as needed.

I have tried with NewtonSoft, but no success. I added a custom contract resolver to serialize private fields, but then I hit an infinite loop problem.


Sep 29, 2016 at 1:15 AM
Hi Bryan,

Unfortunately no, the rules cannot be serialized...

You would have to do that yourself

1. Come up with a Model that is serializable
2. Come up with a Translator that translate the Model into Rules that you feed into the engine.

E.g. Model (in JSON)
"RuleGroup" : {
"Object" : "Person"
"Rules" : [
"Rule" : "MustBeEqual"
"Property" : "Name"
"ConstructorArguments" : [{"Dave"}]
"Rule" : "MustBeLessThanOrEqual"
"Property" : "Age"
"ConstructorArguments" : [{25}]

From that model, your translator should then (perhaps with the help of some Reflection) Create Rule objects and add them to a Rule Engine.