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


C# Compiler.CastToObject方法代码示例

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


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

示例1: EmitWrite

 public void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     ctx.LoadValue(valueFrom);
     ctx.CastToObject(type);
     ctx.LoadReaderWriter();
     ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
     ctx.LoadValue((int)options);
     ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("WriteNetObject"));
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:9,代码来源:NetObjectSerializer.cs

示例2: EmitRead

 public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     ctx.LoadValue(valueFrom);
     ctx.CastToObject(type);
     ctx.LoadReaderWriter();
     ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key));
     if (type ==  ctx.MapType(typeof(object))) ctx.LoadNullRef();
     else ctx.LoadValue(type);
     ctx.LoadValue((int)options);
     ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("ReadNetObject"));
     ctx.CastFromObject(type);
 }
开发者ID:he0x,项目名称:xRAT,代码行数:12,代码来源:NetObjectSerializer.cs

示例3: EmitRead

        public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            ctx.LoadValue(valueFrom);
            ctx.CastToObject(type);
            ctx.LoadReaderWriter();
            ctx.LoadValue(key);
            
			if (type == typeof(object))
            {
            	ctx.LoadNullRef();
            }
            else
            {
            	ctx.LoadValue(type);
            }

            ctx.LoadValue((int)options);
            ctx.EmitCall(typeof(BclHelpers).GetMethod("ReadNetObject"));
            ctx.CastFromObject(type);
        }
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:20,代码来源:NetObjectSerializer.cs

示例4:

 void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     if (!EmitDedicatedMethod(ctx, valueFrom, true))
     {
         ctx.LoadValue(valueFrom);
         if (type.IsValueType) ctx.CastToObject(type);
         ctx.LoadValue(key);
         ctx.LoadReaderWriter();
         ctx.EmitCall(typeof(ProtoReader).GetMethod("ReadObject"));
         ctx.CastFromObject(type);
     }
 }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:12,代码来源:SubItemSerializer.cs

示例5: GetTypeCode

 void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     TypeCode typeCode = GetTypeCode();
     if (map == null)
     {
         ctx.LoadValue(valueFrom);
         ctx.ConvertToInt32(typeCode);
         ctx.EmitBasicWrite("WriteInt32", null);
     }
     else
     {
         using (Compiler.Local loc = ctx.GetLocalWithValue(ExpectedType, valueFrom))
         {
             Compiler.CodeLabel @continue = ctx.DefineLabel();
             for (int i = 0; i < map.Length; i++)
             {
                 Compiler.CodeLabel tryNextValue = ctx.DefineLabel(), processThisValue = ctx.DefineLabel();
                 ctx.LoadValue(loc);
                 WriteEnumValue(ctx, typeCode, map[i].Value);
                 ctx.BranchIfEqual(processThisValue, true);
                 ctx.Branch(tryNextValue, true);
                 ctx.MarkLabel(processThisValue);
                 ctx.LoadValue(map[i].WireValue);
                 ctx.EmitBasicWrite("WriteInt32", null);
                 ctx.Branch(@continue, false);
                 ctx.MarkLabel(tryNextValue);
             }
             ctx.LoadReaderWriter();
             ctx.LoadValue(loc);
             ctx.CastToObject(ExpectedType);
             ctx.EmitCall(typeof(ProtoWriter).GetMethod("ThrowEnumException"));
             ctx.MarkLabel(@continue);
         }
     }
     
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:36,代码来源:EnumSerializer.cs

示例6: 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

示例7:

 void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     if (!EmitDedicatedMethod(ctx, valueFrom, true))
     {
         ctx.LoadValue(valueFrom);
         if (type.IsValueType) ctx.CastToObject(type);
         ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key)); // re-map for formality, but would expect identical, else dedicated method
         ctx.LoadReaderWriter();
         ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("ReadObject"));
         ctx.CastFromObject(type);
     }
 }
开发者ID:tsuixl,项目名称:Frame,代码行数:12,代码来源:SubItemSerializer.cs

示例8:

 void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     if (!EmitDedicatedMethod(ctx, valueFrom, false))
     {
         ctx.LoadValue(valueFrom);
         if (type.IsValueType) ctx.CastToObject(type);
         ctx.LoadValue(key);
         ctx.LoadReaderWriter();
         ctx.EmitCall(typeof(ProtoWriter).GetMethod(recursionCheck ?  "WriteObject" : "WriteRecursionSafeObject"));
     }
 }
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:11,代码来源:SubItemSerializer.cs

示例9: EmitRead


//.........这里部分代码省略.........
							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);

						// field = source.ReadFieldHeader();
						ctx.LoadReaderWriter();
						ctx.EmitCall(typeof (ProtoReader).GetMethod("ReadFieldHeader"));
						ctx.StoreValue(fieldNumber);
						ctx.Branch(processField, false);

						ctx.MarkLabel(@endWhileLoop);
					}

					for (int i = 0; i < locals.Length; i++)
					{
						ctx.LoadValue(locals[i]);
					}

					ctx.EmitCtor(ctor);
					ctx.StoreValue(objValue);

					if (issueReferenceDirectives)
					{
						//source.NetCache.UpdateKeyedObject(tupleKey, oldTuple, result);
						ctx.LoadReaderWriter();
						ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
						ctx.LoadValue(tupleKey);
						ctx.LoadValue(oldTuple);
						ctx.LoadValue(objValue);
						ctx.CastToObject(ExpectedType);
						ctx.EmitCall(typeof (NetObjectCache).GetMethod("UpdateKeyedObject"));
					}

					if (forceIssueFakeHeader)
					{
						//source.ReadEndGroupFieldHeaderHack();
						ctx.LoadReaderWriter();
						ctx.EmitCall(typeof (ProtoReader).GetMethod("ReadEndGroupFieldHeaderHack"));
					}

					ctx.MarkLabel(@end);
					ctx.LoadValue(objValue);
				}
				finally
				{
					for (int i = 0; i < locals.Length; i++)
					{
						if (locals[i] != null)
							locals[i].Dispose(); // release for re-use
					}
				}
			}
        }
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:101,代码来源:TupleSerializer.cs

示例10: 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

示例11:

 void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     if (!EmitDedicatedMethod(ctx, valueFrom, false))
     {
         ctx.LoadValue(valueFrom);
         if (Helpers.IsValueType(type)) ctx.CastToObject(type);
         ctx.LoadValue(ctx.MapMetaKeyToCompiledKey(key)); // re-map for formality, but would expect identical, else dedicated method
         ctx.LoadReaderWriter();
         ctx.EmitCall(Helpers.GetStaticMethod(ctx.MapType(typeof(ProtoWriter)), recursionCheck ?  "WriteObject" : "WriteRecursionSafeObject", new Type[] { ctx.MapType(typeof(object)), ctx.MapType(typeof(int)), ctx.MapType(typeof(ProtoWriter)) }));
     }
 }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:11,代码来源:SubItemSerializer.cs


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