当前位置: 首页>>代码示例>>C#>>正文


C# Compiler.DiscardValue方法代码示例

本文整理汇总了C#中Compiler.DiscardValue方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.DiscardValue方法的具体用法?C# Compiler.DiscardValue怎么用?C# Compiler.DiscardValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compiler的用法示例。


在下文中一共展示了Compiler.DiscardValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
            {
                ctx.LoadAddress(loc, ExpectedType);
                if (Tail.RequiresOldValue)
                {
                    ctx.CopyValue();
                    ctx.LoadValue(field);  
                }
                // value is either now on the stack or not needed
                ctx.ReadNullCheckedTail(field.FieldType, Tail, null);

                if (Tail.ReturnsValue)
                {
                    if (field.FieldType.IsValueType)
                    {
                        // stack is now the return value
                        ctx.StoreValue(field);
                    }
                    else
                    {
                        
                        Compiler.CodeLabel hasValue = ctx.DefineLabel(), allDone = ctx.DefineLabel();
                        ctx.CopyValue();
                        ctx.BranchIfTrue(hasValue, true); // interpret null as "don't assign"

                        // no value, discard
                        ctx.DiscardValue();
                        ctx.DiscardValue();
                        ctx.Branch(allDone, true);

                        ctx.MarkLabel(hasValue);
                        ctx.StoreValue(field);
                        ctx.MarkLabel(allDone);
                    }
                }
                else
                {
                    ctx.DiscardValue();
                }
            }
        }
开发者ID:Rasarack,项目名称:SteamBot,代码行数:43,代码来源:FieldDecorator.cs

示例2: EmitRead

 protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     Tail.EmitRead(ctx, valueFrom);
     ctx.CopyValue();
     Compiler.CodeLabel @nonEmpty = ctx.DefineLabel(), @end = ctx.DefineLabel();
     ctx.LoadValue(typeof(string).GetProperty("Length"));
     ctx.BranchIfTrue(@nonEmpty, true);
     ctx.DiscardValue();
     ctx.LoadNullRef();
     ctx.Branch(@end, true);
     ctx.MarkLabel(@nonEmpty);
     ctx.EmitCtor(typeof(Uri), typeof(string));
     ctx.MarkLabel(@end);
     
 }
开发者ID:Rasarack,项目名称:SteamBot,代码行数:15,代码来源:UriDecorator.cs

示例3: EmitWrite

 protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     Compiler.CodeLabel done = ctx.DefineLabel();
     if (valueFrom == null)
     {
         ctx.CopyValue(); // on the stack
         Compiler.CodeLabel needToPop = ctx.DefineLabel();
         EmitBranchIfDefaultValue(ctx, needToPop);
         Tail.EmitWrite(ctx, null);
         ctx.Branch(done, true);
         ctx.MarkLabel(needToPop);
         ctx.DiscardValue();
     }
     else
     {
         ctx.LoadValue(valueFrom); // variable/parameter
         EmitBranchIfDefaultValue(ctx, done);
         Tail.EmitWrite(ctx, valueFrom);
     }
     ctx.MarkLabel(done);
 }
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:21,代码来源:DefaultValueDecorator.cs

示例4: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            using (Compiler.Local oldList = AppendToCollection ? ctx.GetLocalWithValue(ExpectedType, valueFrom) : null)
            using(Compiler.Local builder = new Compiler.Local(ctx, builderFactory.ReturnType))
            {
                ctx.EmitCall(builderFactory);
                ctx.StoreValue(builder);

                if(AppendToCollection)
                {
                    Compiler.CodeLabel done = ctx.DefineLabel();
                    if(!ExpectedType.IsValueType)
                    {
                        ctx.LoadValue(oldList);
                        ctx.BranchIfFalse(done, false); // old value null; nothing to add
                    }
                    PropertyInfo prop = Helpers.GetProperty(ExpectedType, "Length", false);
                    if(prop == null) prop = Helpers.GetProperty(ExpectedType, "Count", false);
#if !NO_GENERICS
                    if (prop == null) prop = Helpers.GetProperty(ResolveIReadOnlyCollection(ExpectedType, Tail.ExpectedType), "Count", false);
#endif
                    ctx.LoadAddress(oldList, oldList.Type);
                    ctx.EmitCall(Helpers.GetGetMethod(prop, false, false));
                    ctx.BranchIfFalse(done, false); // old list is empty; nothing to add

                    Type voidType = ctx.MapType(typeof(void));
                    if(addRange != null)
                    {
                        ctx.LoadValue(builder);
                        ctx.LoadValue(oldList);
                        ctx.EmitCall(addRange);
                        if (addRange.ReturnType != null && add.ReturnType != voidType) ctx.DiscardValue();
                    }
                    else
                    {
                        // loop and call Add repeatedly
                        MethodInfo moveNext, current, getEnumerator = GetEnumeratorInfo(ctx.Model, out moveNext, out current);
                        Helpers.DebugAssert(moveNext != null);
                        Helpers.DebugAssert(current != null);
                        Helpers.DebugAssert(getEnumerator != null);

                        Type enumeratorType = getEnumerator.ReturnType;
                        using (Compiler.Local iter = new Compiler.Local(ctx, enumeratorType))
                        {
                            ctx.LoadAddress(oldList, ExpectedType);
                            ctx.EmitCall(getEnumerator);
                            ctx.StoreValue(iter);
                            using (ctx.Using(iter))
                            {
                                Compiler.CodeLabel body = ctx.DefineLabel(), next = ctx.DefineLabel();
                                ctx.Branch(next, false);

                                ctx.MarkLabel(body);
                                ctx.LoadAddress(builder, builder.Type);
                                ctx.LoadAddress(iter, enumeratorType);                                
                                ctx.EmitCall(current);
                                ctx.EmitCall(add);
                                if (add.ReturnType != null && add.ReturnType != voidType) ctx.DiscardValue();

                                ctx.MarkLabel(@next);
                                ctx.LoadAddress(iter, enumeratorType);
                                ctx.EmitCall(moveNext);
                                ctx.BranchIfTrue(body, false);
                            }
                        }
                    }


                    ctx.MarkLabel(done);
                }

                EmitReadList(ctx, builder, Tail, add, packedWireType, false);

                ctx.LoadAddress(builder, builder.Type);
                ctx.EmitCall(finish);
                if(ExpectedType != finish.ReturnType)
                {
                    ctx.Cast(ExpectedType);
                }
            }
        }
开发者ID:Erguotou,项目名称:protobuf-net,代码行数:81,代码来源:ImmutableCollectionDecorator.cs

示例5: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            bool writeValue;
            SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
            if (ExpectedType.IsValueType && valueFrom == null)
            {
                throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
            }

            using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
            {
                if (Tail.RequiresOldValue)
                {
                    ctx.LoadAddress(loc, ExpectedType); // stack is: old-addr
                    ctx.LoadValue(property); // stack is: old-value
                }
                Type propertyType = property.PropertyType;
                ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [new-value]

                if (writeValue)
                {
                    using (Compiler.Local newVal = new Compiler.Local(ctx, property.PropertyType))
                    {
                        ctx.StoreValue(newVal); // stack is empty

                        Compiler.CodeLabel allDone = new Compiler.CodeLabel(); // <=== default structs
                        if (!propertyType.IsValueType)
                        { // if the tail returns a null, intepret that as *no assign*
                            allDone = ctx.DefineLabel();
                            ctx.LoadValue(newVal); // stack is: new-value
                            ctx.BranchIfFalse(@allDone, true); // stack is empty
                        }
                        // assign the value
                        ctx.LoadAddress(loc, ExpectedType); // parent-addr
                        ctx.LoadValue(newVal); // parent-obj|new-value
                        if (shadowSetter == null)
                        {
                            ctx.StoreValue(property); // empty
                        }
                        else
                        {
                            ctx.EmitCall(shadowSetter); // empty
                        }
                        if (!propertyType.IsValueType)
                        {
                            ctx.MarkLabel(allDone);
                        }
                    }

                }
                else
                { // don't want return value; drop it if anything there
                    // stack is [new-value]
                    if (Tail.ReturnsValue) { ctx.DiscardValue(); }
                }
            }
        }
开发者ID:he0x,项目名称:xRAT,代码行数:57,代码来源:PropertyDecorator.cs

示例6: EmitRead


//.........这里部分代码省略.........
                    {
                        ctx.LoadAddress(objValue, ExpectedType);
                        ctx.BranchIfFalse(skipOld, false);
                    }
                    for (int i = 0; i < members.Length; i++)
                    {
                        ctx.LoadAddress(objValue, ExpectedType);
                        if (members[i] is FieldInfo)
                        {
                            ctx.LoadValue((FieldInfo)members[i]);
                        }
                        else if (members[i] is PropertyInfo)
                        {
                            ctx.LoadValue((PropertyInfo)members[i]);
                        }
                        ctx.StoreValue(locals[i]);
                    }

                    if (!Helpers.IsValueType(ExpectedType)) ctx.MarkLabel(skipOld);

                    using (Compiler.Local fieldNumber = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
                    {
                        Compiler.CodeLabel @continue = ctx.DefineLabel(),
                                           processField = ctx.DefineLabel(),
                                           notRecognised = ctx.DefineLabel();
                        ctx.Branch(@continue, false);

                        Compiler.CodeLabel[] handlers = new Compiler.CodeLabel[members.Length];
                        for (int i = 0; i < members.Length; i++)
                        {
                            handlers[i] = ctx.DefineLabel();
                        }

                        ctx.MarkLabel(processField);

                        ctx.LoadValue(fieldNumber);
                        ctx.LoadValue(1);
                        ctx.Subtract(); // jump-table is zero-based
                        ctx.Switch(handlers);

                        // and the default:
                        ctx.Branch(notRecognised, false);
                        for (int i = 0; i < handlers.Length; i++)
                        {
                            ctx.MarkLabel(handlers[i]);
                            IProtoSerializer tail = tails[i];
                            Compiler.Local oldValIfNeeded = tail.RequiresOldValue ? locals[i] : null;
                            ctx.ReadNullCheckedTail(locals[i].Type, tail, oldValIfNeeded);
                            if (tail.ReturnsValue)
                            {
                                if (Helpers.IsValueType(locals[i].Type))
                                {
                                    ctx.StoreValue(locals[i]);
                                }
                                else
                                {
                                    Compiler.CodeLabel hasValue = ctx.DefineLabel(), allDone = ctx.DefineLabel();

                                    ctx.CopyValue();
                                    ctx.BranchIfTrue(hasValue, true); // interpret null as "don't assign"
                                    ctx.DiscardValue();
                                    ctx.Branch(allDone, true);
                                    ctx.MarkLabel(hasValue);
                                    ctx.StoreValue(locals[i]);
                                    ctx.MarkLabel(allDone);
                                }
                            }
                            ctx.Branch(@continue, false);
                        }

                        ctx.MarkLabel(notRecognised);
                        ctx.LoadReaderWriter();
                        ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));

                        ctx.MarkLabel(@continue);
                        ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
                        ctx.CopyValue();
                        ctx.StoreValue(fieldNumber);
                        ctx.LoadValue(0);
                        ctx.BranchIfGreater(processField, false);
                    }
                    for (int i = 0; i < locals.Length; i++)
                    {
                        ctx.LoadValue(locals[i]);
                    }

                    ctx.EmitCtor(ctor);
                    ctx.StoreValue(objValue);
                }
                finally
                {
                    for (int i = 0; i < locals.Length; i++)
                    {
                        if (locals[i] != null)
                            locals[i].Dispose(); // release for re-use
                    }
                }
            }

        }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:101,代码来源:TupleSerializer.cs

示例7: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {

            bool writeValue;
            SanityCheck(ctx.Model, property, Tail, out writeValue, ctx.NonPublic, ctx.AllowInternal(property));
            if (ExpectedType.IsValueType && valueFrom == null)
            {
                throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
            }

            ctx.LoadAddress(valueFrom, ExpectedType); // stack is: old-addr
            if (writeValue && Tail.RequiresOldValue)
            { // need to read and write
                ctx.CopyValue();
            }
            // stack is: [old-addr]|old-addr
            if (Tail.RequiresOldValue)
            {
                ctx.LoadValue(property); // stack is: [old-addr]|old-value
            }
            Type propertyType = property.PropertyType;
            ctx.ReadNullCheckedTail(propertyType, Tail, null); // stack is [old-addr]|[new-value]
            
            if (writeValue)
            {
                // stack is old-addr|new-value
                Compiler.CodeLabel @skip = new Compiler.CodeLabel(), allDone = new Compiler.CodeLabel(); // <=== default structs
                if (!propertyType.IsValueType)
                { // if the tail returns a null, intepret that as *no assign*
                    ctx.CopyValue(); // old-addr|new-value|new-value
                    @skip = ctx.DefineLabel();
                    allDone = ctx.DefineLabel();
                    ctx.BranchIfFalse(@skip, true); // old-addr|new-value
                }
                
                if (shadowSetter == null)
                {
                    ctx.StoreValue(property);
                }
                else
                {
                    ctx.EmitCall(shadowSetter);
                }
                if (!propertyType.IsValueType)
                {
                    ctx.Branch(allDone, true);

                    ctx.MarkLabel(@skip); // old-addr|new-value
                    ctx.DiscardValue();
                    ctx.DiscardValue();

                    ctx.MarkLabel(allDone);
                }

            }
            else
            { // don't want return value; drop it if anything there
                // stack is [new-value]
                if (Tail.ReturnsValue) { ctx.DiscardValue(); }
            }
        }
开发者ID:tsuixl,项目名称:Frame,代码行数:61,代码来源:PropertyDecorator.cs

示例8: EmitReadAndAddItem

 private static void EmitReadAndAddItem(Compiler.CompilerContext ctx, Compiler.Local list, IProtoSerializer tail, MethodInfo add)
 {
     ctx.LoadValue(list);
     Type itemType = tail.ExpectedType;
     if (tail.RequiresOldValue)
     {
         if (itemType.IsValueType || !tail.ReturnsValue)
         {
             // going to need a variable
             using (Compiler.Local item = new Compiler.Local(ctx, itemType))
             {
                 if (itemType.IsValueType)
                 {   // initialise the struct
                     ctx.LoadAddress(item, itemType);
                     ctx.EmitCtor(itemType);
                 }
                 else
                 {   // assign null
                     ctx.LoadNullRef();
                     ctx.StoreValue(item);
                 }
                 tail.EmitRead(ctx, item);
                 if (!tail.ReturnsValue) { ctx.LoadValue(item); }
             }
         }
         else
         {    // no variable; pass the null on the stack and take the value *off* the stack
             ctx.LoadNullRef();
             tail.EmitRead(ctx, null);
         }
     }
     else
     {
         if (tail.ReturnsValue)
         {   // out only (on the stack); just emit it
             tail.EmitRead(ctx, null);
         }
         else
         {   // doesn't take anything in nor return anything! WTF?
             throw new InvalidOperationException();
         }
     }
     // our "Add" is chosen either to take the correct type, or to take "object";
     // we may need to box the value
         
     Type addParamType = add.GetParameters()[0].ParameterType;
     if(addParamType != itemType) {
         if (addParamType == typeof(object))
         {
             ctx.CastToObject(itemType);
         }
         else
         {
             throw new InvalidOperationException("Conflicting item/add type");
         }
     }
     ctx.EmitCall(add);
     if (add.ReturnType != typeof(void))
     {
         ctx.DiscardValue();
     }
 }
开发者ID:KimimaroTsukimiya,项目名称:SteamBot-1,代码行数:62,代码来源:ListDecorator.cs

示例9: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {

            bool writeValue;
            SanityCheck(property, Tail, out writeValue, ctx.NonPublic);
            if (ExpectedType.IsValueType && valueFrom == null)
            {
                throw new InvalidOperationException("Attempt to mutate struct on the head of the stack; changes would be lost");
            }

            ctx.LoadAddress(valueFrom, ExpectedType); // stack is: old-addr
            if (writeValue && Tail.RequiresOldValue)
            { // need to read and write
                ctx.CopyValue();
            }
            // stack is: [old-addr]|old-addr
            if (Tail.RequiresOldValue)
            {
                ctx.LoadValue(property); // stack is: [old-addr]|old-value
            }
            ctx.ReadNullCheckedTail(property.PropertyType, Tail, null); // stack is [old-addr]|[new-value]
            
            if (writeValue)
            {   // stack is old-addr|new-value
                ctx.StoreValue(property);
            }
            else
            { // don't want return value; drop it if anything there
                // stack is [new-value]
                if (Tail.ReturnsValue) { ctx.DiscardValue(); }
            }
        }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:32,代码来源:PropertyDecorator.cs

示例10: EmitInvokeCallback

 void IProtoTypeSerializer.EmitCallback(Compiler.CompilerContext ctx, Compiler.Local valueFrom, TypeModel.CallbackType callbackType)
 {
     Helpers.DebugAssert(((IProtoTypeSerializer)this).HasCallbacks(callbackType), "Shouldn't be calling this if there is nothing to do");
     MethodInfo method = callbacks == null ? null : callbacks[callbackType];
     ctx.LoadValue(valueFrom);
     EmitInvokeCallback(ctx, method);
     Compiler.CodeLabel @break = ctx.DefineLabel();
     if (CanHaveInheritance)
     {
         for (int i = 0; i < serializers.Length; i++)
         {
             IProtoSerializer ser = serializers[i];
             IProtoTypeSerializer typeser;
             if (ser.ExpectedType != forType && (typeser = (IProtoTypeSerializer)ser).HasCallbacks(callbackType))
             {
                 Compiler.CodeLabel ifMatch = ctx.DefineLabel(), nextTest = ctx.DefineLabel();
                 ctx.CopyValue();
                 ctx.TryCast(ser.ExpectedType);
                 ctx.CopyValue();
                 ctx.BranchIfTrue(ifMatch, true);
                 ctx.DiscardValue();
                 ctx.Branch(nextTest, false);
                 ctx.MarkLabel(ifMatch);
                 typeser.EmitCallback(ctx, null, callbackType);
                 ctx.Branch(@break, false);
                 ctx.MarkLabel(nextTest);
             }
         }
     }
     ctx.MarkLabel(@break);
     ctx.DiscardValue();
 }
开发者ID:helios57,项目名称:anrl,代码行数:32,代码来源:TypeSerializer.cs

示例11: using

        void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            Type expected = ExpectedType;
            using (Compiler.Local loc = ctx.GetLocalWithValue(expected, valueFrom))
            {
                // pre-callbacks
                EmitCallbackIfNeeded(ctx, loc, TypeModel.CallbackType.BeforeSerialize);

                Compiler.CodeLabel startFields = ctx.DefineLabel();
                // inheritance
                if (CanHaveInheritance)
                {
                    for (int i = 0; i < serializers.Length; i++)
                    {
                        IProtoSerializer ser = serializers[i];
                        if (ser.ExpectedType != forType)
                        {
                            Compiler.CodeLabel ifMatch = ctx.DefineLabel(), nextTest = ctx.DefineLabel();
                            ctx.LoadValue(loc);
                            ctx.TryCast(ser.ExpectedType);
                            ctx.CopyValue();
                            ctx.BranchIfTrue(ifMatch, true);
                            ctx.DiscardValue();
                            ctx.Branch(nextTest, true);
                            ctx.MarkLabel(ifMatch);
                            ser.EmitWrite(ctx, null);
                            ctx.Branch(startFields, false);
                            ctx.MarkLabel(nextTest);
                        }
                    }

                    if (constructType != null && constructType != forType)
                    {
                        using(Compiler.Local actualType = new Compiler.Local(ctx, typeof(Type)))
                        {
                            // would have jumped to "fields" if an expected sub-type, so two options:
                            // a: *exactly* that type, b: an *unexpected* type
                            ctx.LoadValue(loc);
                            ctx.EmitCall(typeof(object).GetMethod("GetType"));
                            ctx.CopyValue();
                            ctx.StoreValue(actualType);
                            ctx.LoadValue(forType);
                            ctx.BranchIfEqual(startFields, true);

                            ctx.LoadValue(actualType);
                            ctx.LoadValue(constructType);
                            ctx.BranchIfEqual(startFields, true);
                        }
                    }
                    else
                    {
                        // would have jumped to "fields" if an expected sub-type, so two options:
                        // a: *exactly* that type, b: an *unexpected* type
                        ctx.LoadValue(loc);
                        ctx.EmitCall(typeof(object).GetMethod("GetType"));
                        ctx.LoadValue(forType);
                        ctx.BranchIfEqual(startFields, true);
                    }
                    // unexpected, then... note that this *might* be a proxy, which
                    // is handled by ThrowUnexpectedSubtype
                    ctx.LoadValue(forType);
                    ctx.LoadValue(loc);
                    ctx.EmitCall(typeof(object).GetMethod("GetType"));
                    ctx.EmitCall(typeof(TypeModel).GetMethod("ThrowUnexpectedSubtype",
                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static));

                }
                // fields

                ctx.MarkLabel(startFields);
                for (int i = 0; i < serializers.Length; i++)
                {
                    IProtoSerializer ser = serializers[i];
                    if (ser.ExpectedType == forType) ser.EmitWrite(ctx, loc);
                }

                // extension data
                if (isExtensible)
                {
                    ctx.LoadValue(loc);
                    ctx.LoadReaderWriter();
                    ctx.EmitCall(typeof(ProtoWriter).GetMethod("AppendExtensionData"));
                }
                // post-callbacks
                EmitCallbackIfNeeded(ctx, loc, TypeModel.CallbackType.AfterSerialize);
            }
        }
开发者ID:helios57,项目名称:anrl,代码行数:87,代码来源:TypeSerializer.cs

示例12: EmitRead


//.........这里部分代码省略.........
						{
							handlers[i] = ctx.DefineLabel();
						}

						ctx.MarkLabel(processField);

						ctx.LoadValue(fieldNumber);
						ctx.LoadValue(1);
						ctx.Subtract(); // jump-table is zero-based
						ctx.Switch(handlers);

						// and the default:
						ctx.Branch(notRecognised, false);

						for (int i = 0; i < handlers.Length; i++)
						{
							ctx.MarkLabel(handlers[i]);
							IProtoSerializer tail = tails[i];
							Compiler.Local oldValIfNeeded = tail.RequiresOldValue ? locals[i] : null;
							ctx.ReadNullCheckedTail(locals[i].Type, tail, oldValIfNeeded);

							if (tail.ReturnsValue)
							{
								if (locals[i].Type.IsValueType)
								{
									ctx.StoreValue(locals[i]);
								}
								else
								{
									Compiler.CodeLabel hasValue = ctx.DefineLabel(), allDone = ctx.DefineLabel();

									ctx.CopyValue();
									ctx.BranchIfTrue(hasValue, true); // interpret null as "don't assign"
									ctx.DiscardValue();
									ctx.Branch(allDone, true);
									ctx.MarkLabel(hasValue);
									ctx.StoreValue(locals[i]);
									ctx.MarkLabel(allDone);
								}
							}

							ctx.Branch(@continue, false);
						}

						ctx.MarkLabel(notRecognised);
						ctx.LoadReaderWriter();
						ctx.EmitCall(typeof (ProtoReader).GetMethod("SkipField"));

						ctx.MarkLabel(@continue);

						// j < values.Length
						ctx.LoadValue(j);
						ctx.LoadValue(members.Length);
						ctx.BranchIfGreaterOrEqual(@endWhileLoop, false);

						//j++
						ctx.LoadValue(j);
						ctx.LoadValue(1);
						ctx.Add();
						ctx.StoreValue(j);

						// source.ReadNextFieldHack() > 0
						ctx.LoadReaderWriter();
						ctx.EmitCall(typeof (ProtoReader).GetMethod("ReadNextFieldHack"));
						ctx.LoadValue(0);
						ctx.BranchIfLessOrEqual(@endWhileLoop, true);
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:67,代码来源:TupleSerializer.cs

示例13: EmitWrite

        public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
        	Compiler.CodeLabel @end = ctx.DefineLabel();

        	using (Compiler.Local value = ctx.GetLocalWithValue(ctor.DeclaringType, valueFrom))
            {
				if (!baseTupleAsReference && asReference)
				{
					using (Compiler.Local existing = new Compiler.Local(ctx, typeof(bool)))
					using (Compiler.Local tupleKey = new Compiler.Local(ctx, typeof(int)))
					{
						//int tupleKey = dest.NetCache.AddObjectKey(value, out existing);
						ctx.LoadReaderWriter();
						ctx.LoadValue(typeof(ProtoWriter).GetProperty("NetCache"));
						ctx.LoadValue(value);
						ctx.CastToObject(ctor.DeclaringType); // HACK : doesn't seem to get boxed from ctx.GetLocalWithValue
						ctx.LoadAddress(existing, typeof(bool));
						ctx.EmitCall(typeof(NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() }));
						ctx.StoreValue(tupleKey);

						//ProtoWriter.WriteUInt32(existing ? (uint) tupleKey : 0, dest);
						Compiler.CodeLabel @continueBranch = ctx.DefineLabel();
						ctx.LoadValue(0);
						ctx.LoadValue(existing);
						ctx.BranchIfFalse(@continueBranch, true);
						ctx.DiscardValue();
						ctx.LoadValue(tupleKey);
						//ctx.CastToObject(typeof(uint));
						ctx.MarkLabel(@continueBranch);
						ctx.LoadReaderWriter();
						ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteUInt32"));

						//if (existing) { return; }
						ctx.LoadValue(existing);
						ctx.BranchIfTrue(@end, false);
					}
				}

                for (int i = 0; i < tails.Length; i++)
                {
                    Type type = GetMemberType(i);
                    ctx.LoadAddress(value, ExpectedType);
                    switch(members[i].MemberType)
                    {
                        case MemberTypes.Field:
                            ctx.LoadValue((FieldInfo)members[i]);
                            break;
                        case MemberTypes.Property:
                            ctx.LoadValue((PropertyInfo)members[i]);
                            break;
                    }
                    ctx.WriteNullCheckedTail(type, tails[i], null);
                }
            }

			if (forceIssueFakeHeader)
			{
				ctx.LoadReaderWriter();
				ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteEndGroupFieldHeaderHack"));
			}

			ctx.MarkLabel(@end);
        }
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:63,代码来源:TupleSerializer.cs


注:本文中的Compiler.DiscardValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。