本文整理汇总了C#中Compiler.CastFromObject方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.CastFromObject方法的具体用法?C# Compiler.CastFromObject怎么用?C# Compiler.CastFromObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.CastFromObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3:
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);
}
}
示例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(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);
}
}
示例5: EmitRead
public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local incoming)
{
bool issueReferenceDirectives = !baseTupleAsReference && asReference;
Compiler.CodeLabel @end = ctx.DefineLabel();
using (Compiler.Local tupleKey = new Compiler.Local(ctx, typeof(int)))
using (Compiler.Local oldTuple = new Compiler.Local(ctx, typeof(object)))
using (Compiler.Local objValue = ctx.GetLocalWithValue(ExpectedType, incoming))
{
Compiler.Local[] locals = new Compiler.Local[members.Length];
try
{
if (issueReferenceDirectives)
{
//int tupleKey = 0;
ctx.LoadValue(0);
ctx.StoreValue(tupleKey);
//object oldTuple = null;
ctx.LoadNullRef();
ctx.StoreValue(oldTuple);
//tupleKey = (int)source.ReadUInt32();
ctx.LoadReaderWriter();
ctx.EmitCall(typeof (ProtoReader).GetMethod("ReadUInt32"));
//ctx.CastToObject(typeof (int));
ctx.StoreValue(tupleKey);
Compiler.CodeLabel @objectNotFound = ctx.DefineLabel();
ctx.LoadValue(tupleKey);
ctx.LoadValue(0);
ctx.BranchIfEqual(@objectNotFound, true);
//// return source.NetCache.GetKeyedObject(tupleKey);
ctx.LoadReaderWriter();
ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
ctx.LoadValue(tupleKey);
ctx.EmitCall(typeof (NetObjectCache).GetMethod("GetKeyedObject"));
ctx.CastFromObject(ExpectedType);
ctx.StoreValue(objValue);
ctx.Branch(@end, false);
ctx.MarkLabel(@objectNotFound);
ctx.EmitCtor(typeof (object));
ctx.StoreValue(oldTuple);
// tupleKey = source.NetCache.AddObjectKey(oldTuple, out dummy);
using (Compiler.Local dummy = new Compiler.Local(ctx, typeof (bool)))
{
ctx.LoadReaderWriter();
ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
ctx.LoadValue(oldTuple);
ctx.LoadAddress(dummy, typeof (bool));
ctx.EmitCall(typeof (NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() }));
ctx.StoreValue(tupleKey);
}
}
for (int i = 0; i < locals.Length; i++)
{
Type type = GetMemberType(i);
bool store = true;
locals[i] = new Compiler.Local(ctx, type);
if (!ExpectedType.IsValueType)
{
// value-types always read the old value
if (type.IsValueType)
{
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Int16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.SByte:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.UInt32:
ctx.LoadValue(0);
break;
case ProtoTypeCode.Int64:
case ProtoTypeCode.UInt64:
ctx.LoadValue(0L);
break;
case ProtoTypeCode.Single:
ctx.LoadValue(0.0F);
break;
case ProtoTypeCode.Double:
ctx.LoadValue(0.0D);
break;
case ProtoTypeCode.Decimal:
ctx.LoadValue(0M);
break;
case ProtoTypeCode.Guid:
ctx.LoadValue(Guid.Empty);
break;
default:
ctx.LoadAddress(locals[i], type);
//.........这里部分代码省略.........