public CodegenExpression CodegenDeserialize(
            CodegenMethod method,
            CodegenClassScope classScope,
            CodegenExpression elementExpr)
        {
            var mapType = typeof(IDictionary <,>).MakeGenericType(typeof(string), _valueType);
            var child   = method
                          .MakeChild(mapType, GetType(), classScope)
                          .AddParam <JsonElement>("jsonElement");

            child
            .Block
            .MethodReturn(
                StaticMethod(
                    typeof(JsonElementExtensions),
                    "ElementToDictionary",
                    new[] { _valueType },
                    Ref("jsonElement"),
                    new CodegenExpressionLambda(method.Block)
                    .WithParam <JsonElement>("_")
                    .WithBody(
                        _ => _
                        .BlockReturn(
                            Cast(
                                _valueType,
                                _valueForge.CodegenDeserialize(
                                    child,
                                    classScope,
                                    Ref("_")))))));

            return(LocalMethod(child, elementExpr));
        }
Ejemplo n.º 2
0
        public CodegenExpression CodegenDeserialize(
            CodegenMethod method,
            CodegenClassScope classScope,
            CodegenExpression elementExpr)
        {
            var arrayType = TypeHelper.GetArrayType(_subForgeComponentType);
            var child     = method
                            .MakeChild(arrayType, GetType(), classScope)
                            .AddParam <JsonElement>("jsonElement");

            child
            .Block
            .MethodReturn(
                StaticMethod(
                    typeof(JsonElementExtensions),
                    "ElementToArray",
                    new [] { _subForgeComponentType },
                    Ref("jsonElement"),
                    new CodegenExpressionLambda(method.Block)
                    .WithParam <JsonElement>("_")
                    .WithBody(
                        _ => _.BlockReturn(
                            Cast(
                                _subForgeComponentType,
                                _subForge.CodegenDeserialize(
                                    child,
                                    classScope,
                                    Ref("_")))))));

            return(LocalMethod(child, elementExpr));

#if false
            method
            .Block
            .StaticMethod(
                typeof(JsonElementExtensions),
                "ElementToArray",
                Ref("jsonElement"),
                new CodegenExpressionLambda(method.Block)
                .WithParam <JsonElement>("_")
                .WithBody(_ => _subForge.CodegenDeserialize(method, classScope, Ref("_"))));
#endif
        }