/// <summary> /// Creates a new expression tree serializer instance, initialized with the given rule table. /// </summary> /// <param name="ruleTable">Rule table to use in the serializer instance.</param> /// <param name="typeResolutionService">Type resolution service. Can be null.</param> protected ExpressionJsonSerializer(RuleTableBase <object, Json.Expression, ExpressionJsonSerializationContext> ruleTable, ITypeResolutionService typeResolutionService) : base( () => new ExpressionJsonSerializationContext(), ctx => Json.Expression.Object(new Dictionary <string, Json.Expression> { { "Context", ctx.Context.ToJson() }, { "Value", ctx.Payload } }), json => ((Json.ObjectExpression)json).Members.Let(members => new Contextual <ExpressionJsonSerializationContext, Json.Expression> { Context = ExpressionJsonSerializationContext.FromJson(members["Context"], typeResolutionService), Payload = members["Value"] }), ruleTable) { }
/// <summary> /// Creates a new JSON-based serializer with rules for commonly used (mostly primitive) types from the BCL. /// </summary> /// <param name="newContext">Function to get a new serialization context during serialization.</param> /// <param name="addContext">Function to add serialization context to the serialization output.</param> /// <param name="getContext">Function to get deserialization context from deserialization input.</param> /// <param name="ruleTable">Rule table with serialization and deserialization rules.</param> protected JsonSerializer(Func <TContext> newContext, Func <Contextual <TContext, Json.Expression>, Json.Expression> addContext, Func <Json.Expression, Contextual <TContext, Json.Expression> > getContext, RuleTableBase <object, Json.Expression, TContext> ruleTable) : base( tag => INLINED.Contains(tag.Name) ? tag.Value : Json.Expression.Object( new Dictionary <string, Json.Expression> { { "Type", Json.Expression.String(tag.Name) }, { "Value", tag.Value } } ), json => INLINED.Contains(json.NodeType.ToString()) ? new TaggedByRule <Json.Expression> { Name = ((Json.ConstantExpression)json).NodeType.ToString(), Value = json } : ((Json.ObjectExpression)json).Let(jo => new TaggedByRule <Json.Expression> { Name = (string)((Json.ConstantExpression)jo.Members["Type"]).Value, Value = jo.Members["Value"] }), newContext, addContext, getContext, ruleTable) { }