Ejemplo n.º 1
0
        Action <AbstractBufferedWriter, object> NewSimpleSaver(ITypeDescriptor descriptor)
        {
            if (descriptor.AnyOpNeedsCtx())
            {
                return(null);
            }
            var method = ILBuilder.Instance.NewMethod <Action <AbstractBufferedWriter, object> >(descriptor.Name + "SimpleSaver");
            var il     = method.Generator;

            descriptor.GenerateSave(il, ilgen => ilgen.Ldarg(0), null, ilgen =>
            {
                ilgen.Ldarg(1);
                var type = descriptor.GetPreferredType();
                if (type != typeof(object))
                {
                    ilgen.UnboxAny(type);
                }
            }, descriptor.GetPreferredType());
            il.Ret();
            return(method.Create());
        }
Ejemplo n.º 2
0
        Func <AbstractBufferedReader, ITypeBinaryDeserializerContext, ITypeSerializersId2LoaderMapping, ITypeDescriptor, object> LoaderFactory(ITypeDescriptor descriptor)
        {
            var loadAsType    = LoadAsType(descriptor);
            var methodBuilder = ILBuilder.Instance.NewMethod <Func <AbstractBufferedReader, ITypeBinaryDeserializerContext, ITypeSerializersId2LoaderMapping, ITypeDescriptor, object> >("DeserializerFor" + descriptor.Name);
            var il            = methodBuilder.Generator;

            if (descriptor.AnyOpNeedsCtx())
            {
                var localCtx = il.DeclareLocal(typeof(ITypeBinaryDeserializerContext), "ctx");
                var haveCtx  = il.DefineLabel();
                il
                .Ldarg(1)
                .Dup()
                .Stloc(localCtx)
                .Brtrue(haveCtx)
                .Ldarg(0)
                .Ldarg(2)
                .Newobj(() => new DeserializerCtx(null, null))
                .Castclass(typeof(ITypeBinaryDeserializerContext))
                .Stloc(localCtx)
                .Mark(haveCtx);
                descriptor.GenerateLoad(il, ilGen => ilGen.Ldarg(0), ilGen => ilGen.Ldloc(localCtx), ilGen => ilGen.Ldarg(3), loadAsType);
            }
            else
            {
                descriptor.GenerateLoad(il, ilGen => ilGen.Ldarg(0), ilGen => ilGen.Ldarg(1), ilGen => ilGen.Ldarg(3), loadAsType);
            }
            if (loadAsType.IsValueType)
            {
                il.Box(loadAsType);
            }
            else if (loadAsType != typeof(object))
            {
                il.Castclass(typeof(object));
            }
            il.Ret();
            return(methodBuilder.Create());
        }
Ejemplo n.º 3
0
 public bool AnyOpNeedsCtx()
 {
     return(!_keyDescriptor.StoredInline || !_valueDescriptor.StoredInline ||
            _keyDescriptor.AnyOpNeedsCtx() ||
            _valueDescriptor.AnyOpNeedsCtx());
 }
Ejemplo n.º 4
0
 public bool AnyOpNeedsCtx()
 {
     return(!_itemDescriptor.StoredInline || _itemDescriptor.AnyOpNeedsCtx());
 }
Ejemplo n.º 5
0
 Action<AbstractBufferedWriter, object> NewSimpleSaver(ITypeDescriptor descriptor)
 {
     if (descriptor.AnyOpNeedsCtx()) return null;
     var method = ILBuilder.Instance.NewMethod<Action<AbstractBufferedWriter, object>>(descriptor.Name + "SimpleSaver");
     var il = method.Generator;
     descriptor.GenerateSave(il, ilgen => ilgen.Ldarg(0), null, ilgen =>
         {
             ilgen.Ldarg(1);
             var type = descriptor.GetPreferedType();
             if (type != typeof(object))
             {
                 ilgen.UnboxAny(type);
             }
         }, descriptor.GetPreferedType());
     il.Ret();
     return method.Create();
 }
Ejemplo n.º 6
0
 Func<AbstractBufferedReader, ITypeBinaryDeserializerContext, ITypeSerializersId2LoaderMapping, ITypeDescriptor, object> LoaderFactory(ITypeDescriptor descriptor)
 {
     var loadAsType = LoadAsType(descriptor);
     var methodBuilder = ILBuilder.Instance.NewMethod<Func<AbstractBufferedReader, ITypeBinaryDeserializerContext, ITypeSerializersId2LoaderMapping, ITypeDescriptor, object>>("DeserializerFor" + descriptor.Name);
     var il = methodBuilder.Generator;
     if (descriptor.AnyOpNeedsCtx())
     {
         var localCtx = il.DeclareLocal(typeof(ITypeBinaryDeserializerContext), "ctx");
         var haveCtx = il.DefineLabel();
         il
             .Ldarg(1)
             .Dup()
             .Stloc(localCtx)
             .Brtrue(haveCtx)
             .Ldarg(0)
             .Ldarg(2)
             .Newobj(() => new DeserializerCtx(null, null))
             .Castclass(typeof(ITypeBinaryDeserializerContext))
             .Stloc(localCtx)
             .Mark(haveCtx);
         descriptor.GenerateLoad(il, ilGen => ilGen.Ldarg(0), ilGen => ilGen.Ldloc(localCtx), ilGen => ilGen.Ldarg(3), loadAsType);
     }
     else
     {
         descriptor.GenerateLoad(il, ilGen => ilGen.Ldarg(0), ilGen => ilGen.Ldarg(1), ilGen => ilGen.Ldarg(3), loadAsType);
     }
     if (loadAsType.IsValueType)
     {
         il.Box(loadAsType);
     }
     else if (loadAsType != typeof(object))
     {
         il.Castclass(typeof(object));
     }
     il.Ret();
     return methodBuilder.Create();
 }