Пример #1
0
        bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
        {
#if SILVERLIGHT
            return(false);
#else
            MethodBuilder method = ctx.GetDedicatedMethod(key, read);
            if (method == null)
            {
                return(false);
            }

            using (Compiler.Local token = new UcAsp.RPC.ProtoBuf.Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
            {
                Type rwType = ctx.MapType(read ? typeof(ProtoReader) : typeof(ProtoWriter));
                ctx.LoadValue(valueFrom);
                if (!read) // write requires the object for StartSubItem; read doesn't
                {          // (if recursion-check is disabled [subtypes] then null is fine too)
                    if (Helpers.IsValueType(type) || !recursionCheck)
                    {
                        ctx.LoadNullRef();
                    }
                    else
                    {
                        ctx.CopyValue();
                    }
                }
                ctx.LoadReaderWriter();
                ctx.EmitCall(Helpers.GetStaticMethod(rwType, "StartSubItem",
                                                     read ? new Type[] { rwType } : new Type[] { ctx.MapType(typeof(object)), rwType }));
                ctx.StoreValue(token);

                // note: value already on the stack
                ctx.LoadReaderWriter();
                ctx.EmitCall(method);
                // handle inheritance (we will be calling the *base* version of things,
                // but we expect Read to return the "type" type)
                if (read && type != method.ReturnType)
                {
                    ctx.Cast(this.type);
                }
                ctx.LoadValue(token);
                ctx.LoadReaderWriter();
                ctx.EmitCall(Helpers.GetStaticMethod(rwType, "EndSubItem", new Type[] { ctx.MapType(typeof(SubItemToken)), rwType }));
            }
            return(true);
#endif
        }
Пример #2
0
        bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
        {
            System.Reflection.Emit.MethodBuilder method = ctx.GetDedicatedMethod(key, read);
            if (method == null)
            {
                return(false);
            }

            using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, typeof(SubItemToken)))
            {
                Type rwType = read ? typeof(ProtoReader) : typeof(ProtoWriter);
                ctx.LoadValue(valueFrom);
                if (!read) // write requires the object for StartSubItem; read doesn't
                {          // (if recursion-check is disabled [subtypes] then null is fine too)
                    if (type.IsValueType || !recursionCheck)
                    {
                        ctx.LoadNullRef();
                    }
                    else
                    {
                        ctx.CopyValue();
                    }
                }
                ctx.LoadReaderWriter();
                ctx.EmitCall(rwType.GetMethod("StartSubItem"));
                ctx.StoreValue(token);

                // note: value already on the stack
                ctx.LoadReaderWriter();
                ctx.EmitCall(method);
                // handle inheritance (we will be calling the *base* version of things,
                // but we expect Read to return the "type" type)
                if (read && type != method.ReturnType)
                {
                    ctx.Cast(this.type);
                }
                ctx.LoadValue(token);

                ctx.LoadReaderWriter();
                ctx.EmitCall(rwType.GetMethod("EndSubItem"));
            }
            return(true);
        }
Пример #3
0
        bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
        {
#if SILVERLIGHT
            return(false);
#else
            MethodBuilder method = ctx.GetDedicatedMethod(_baseKey, read);
            if (method == null)
            {
                return(false);
            }

            ctx.LoadValue(valueFrom);
            ctx.LoadReaderWriter();
            ctx.EmitCall(method);
            // handle inheritance (we will be calling the *base* version of things,
            // but we expect Read to return the "type" type)
            if (read && ExpectedType != method.ReturnType)
            {
                ctx.Cast(this.ExpectedType);
            }
#endif
            return(true);
        }
Пример #4
0
        private bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
        {
            MethodBuilder method = ctx.GetDedicatedMethod(key, read);

            if (method == null)
            {
                return(false);
            }

            using (Compiler.Local val = ctx.GetLocalWithValue(type, valueFrom))
                using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, typeof(SubItemToken)))
                {
                    Type rwType = read ? typeof(ProtoReader) : typeof(ProtoWriter);

                    if (read)
                    {
                        ctx.LoadReader(true);
                    }
                    else
                    {
                        // write requires the object for StartSubItem; read doesn't
                        // (if recursion-check is disabled [subtypes] then null is fine too)
                        if (Helpers.IsValueType(type) || !recursionCheck)
                        {
                            ctx.LoadNullRef();
                        }
                        else
                        {
                            ctx.LoadValue(val);
                        }
                        ctx.LoadWriter(true);
                    }
                    ctx.EmitCall(Helpers.GetStaticMethod(rwType, "StartSubItem",
                                                         read ? ProtoReader.State.ReaderStateTypeArray : new Type[] { typeof(object), rwType, ProtoWriter.ByRefStateType }));
                    ctx.StoreValue(token);

                    if (read)
                    {
                        ctx.LoadReader(true);
                        ctx.LoadValue(val);
                    }
                    else
                    {
                        ctx.LoadWriter(true);
                        ctx.LoadValue(val);
                    }
                    ctx.EmitCall(method);
                    // handle inheritance (we will be calling the *base* version of things,
                    // but we expect Read to return the "type" type)
                    if (read && type != method.ReturnType)
                    {
                        ctx.Cast(type);
                    }
                    ctx.LoadValue(token);
                    if (read)
                    {
                        ctx.LoadReader(true);
                        ctx.EmitCall(Helpers.GetStaticMethod(rwType, "EndSubItem",
                                                             new Type[] { typeof(SubItemToken), rwType, ProtoReader.State.ByRefStateType }));
                    }
                    else
                    {
                        ctx.LoadWriter(true);
                        ctx.EmitCall(ProtoWriter.GetStaticMethod("EndSubItem"));
                    }
                }
            return(true);
        }