Exemple #1
0
        public static Func <TFrom, TTo> GetConverter_CompiledFast_LightExpression <TFrom, TTo>()
        {
            var fromParam = L.Parameter(typeof(TFrom));
            var expr      = L.Lambda <Func <TFrom, TTo> >(L.Convert(fromParam, typeof(TTo)), fromParam);

            return(LightExpression.ExpressionCompiler.CompileFast(expr, true));
        }
 public sealed override void EmitWriteValue(Compiler <ObjectWriter> c,
                                            FastExpressionCompiler.LightExpression.Expression stream,
                                            FastExpressionCompiler.LightExpression.Expression fieldValue,
                                            FastExpressionCompiler.LightExpression.Expression session)
 {
     c.EmitStaticCall(_write, stream, fieldValue);
 }
        public object CreateExpressionInfo_and_FastCompile()
        {
            //Expression<Func<Action<string>>> expr = () => a => s.SetValue(a);

            var aParam = LE.Parameter(typeof(string), "a");
            var expr   = LE.Lambda(LE.Lambda(LE.Call(LE.Constant(_s), _setValueMethod, aParam), aParam));

            return(LEC.TryCompile <Func <Action <string> > >(expr));
        }
Exemple #4
0
        public sealed override void EmitWriteValue(Compiler <ObjectWriter> c,
                                                   FastExpressionCompiler.LightExpression.Expression stream,
                                                   FastExpressionCompiler.LightExpression.Expression fieldValue,
                                                   FastExpressionCompiler.LightExpression.Expression session)
        {
            var byteArray = c.GetVariable <byte[]>(SerializerCompiler.PreallocatedByteBuffer);

            c.EmitStaticCall(_write, stream, fieldValue, byteArray);
        }
        private static LightExpression.Expression <Func <Source, Dest, ResolutionContext, Dest> > CreateLightExpression()
        {
            var srcParam  = L.Parameter(typeof(Source), "source");
            var destParam = L.Parameter(typeof(Dest), "dest");

            var exceptionVar     = L.Parameter(typeof(Exception), "ex");
            var typeMapDestVar   = L.Parameter(typeof(Dest), "d");
            var resolvedValueVar = L.Parameter(typeof(int), "val");

            var expression = L.Lambda <Func <Source, Dest, ResolutionContext, Dest> >(
                L.Block(
                    L.Condition(
                        L.Equal(srcParam, L.Constant(null)),
                        L.Default(typeof(Dest)),
                        L.Block(typeof(Dest), new[] { typeMapDestVar },
                                L.Assign(
                                    typeMapDestVar,
                                    L.Coalesce(destParam, L.New(typeof(Dest).GetTypeInfo().DeclaredConstructors.First()))),
                                L.TryCatch(
                                    /* Assign src.Value */
                                    L.Block(new[] { resolvedValueVar },
                                            L.Block(
                                                L.Assign(resolvedValueVar,
                                                         L.Condition(L.Or(L.Equal(srcParam, L.Constant(null)), L.Constant(false)),
                                                                     L.Default(typeof(int)),
                                                                     L.Property(srcParam, "Value"))
                                                         ),
                                                L.Assign(L.Property(typeMapDestVar, "Value"), resolvedValueVar)
                                                )
                                            ),
                                    L.Catch(exceptionVar,
                                            L.Throw(
                                                L.New(typeof(AutoMapperException).GetTypeInfo().DeclaredConstructors.First(),
                                                      L.Constant("Error mapping types."),
                                                      exceptionVar),
                                                typeof(int))) // should skip this, cause does no make sense after the throw
                                    ),
                                typeMapDestVar))
                    ),
                srcParam, destParam, L.Parameter(typeof(ResolutionContext), "_")
                );

            return(expression);
        }
Exemple #6
0
        private LightExpression.Expression <Func <A> > CreateLightExpression()
        {
            var test           = L.Constant(new NestedLambdasVsVars());
            var getOrAddMethod = test.Type.GetMethod(nameof(GetOrAdd));
            var d = L.Convert(
                L.Call(test, getOrAddMethod,
                       L.Constant(2),
                       L.Lambda <Func <object> >(L.New(_dCtor), typeof(object))),
                typeof(D));

            var c = L.Convert(
                L.Call(test, getOrAddMethod,
                       L.Constant(1),
                       L.Lambda <Func <object> >(L.New(_cCtor, d), typeof(object))),
                typeof(C));

            var b = L.Convert(
                L.Call(test, getOrAddMethod,
                       L.Constant(0),
                       L.Lambda <Func <object> >(L.New(_bCtor, c, d), typeof(object))),
                typeof(B));

            return(L.Lambda <Func <A> >(L.New(_aCtor, b, c), typeof(A)));
        }
 public object NewLightExpression()
 {
     return(LE.New(_xCtor, LE.Constant(_y)));
 }
        //[Benchmark]
        public X CreateLightExpression_and_FastCompile_and_Invoke()
        {
            var expr = LE.Lambda <Func <X> >(LE.New(_xCtor, LE.New(_aCtor), LE.New(_bCtor)));

            return(LEC.CompileFast(expr, true).Invoke());
        }
Exemple #9
0
        public sealed override FastExpressionCompiler.LightExpression.Expression EmitReadValue(Compiler <ObjectReader> c,
                                                                                               FastExpressionCompiler.LightExpression.Expression stream,
                                                                                               FastExpressionCompiler.LightExpression.Expression session, FieldInfo field)
        {
            var byteArray = c.GetVariable <byte[]>(SerializerCompiler.PreallocatedByteBuffer);

            return(c.StaticCall(_read, stream, byteArray));
        }
Exemple #10
0
 public object NewExpressionInfo()
 {
     return(LE.New(_xCtor, LE.Constant(_y)));
 }
 public sealed override FastExpressionCompiler.LightExpression.Expression EmitReadValue(Compiler <ObjectReader> c,
                                                                                        FastExpressionCompiler.LightExpression.Expression stream,
                                                                                        FastExpressionCompiler.LightExpression.Expression session, FieldInfo field)
 {
     return(c.StaticCall(_read, stream));
 }
Exemple #12
0
        public object CreateExpressionInfo_and_FastCompile()
        {
            var expr = LE.Lambda(LE.New(_xCtor, LE.New(_aCtor), LE.New(_bCtor)));

            return(LEC.TryCompile <Func <object> >(expr));
        }