本文整理汇总了C#中Compiler.LoadReaderWriter方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.LoadReaderWriter方法的具体用法?C# Compiler.LoadReaderWriter怎么用?C# Compiler.LoadReaderWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.LoadReaderWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitDedicatedMethod
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 (type.IsValueType) { 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;
}
示例2: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();
ctx.MarkLabel(next);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(field);
ctx.LoadValue(Tag); // = 1 - process
ctx.BranchIfEqual(processField, true);
ctx.LoadValue(field);
ctx.LoadValue(1); // < 1 - exit
ctx.BranchIfLess(end, false);
// default: skip
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(next, true);
// process
ctx.MarkLabel(processField);
if (Tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(oldValue, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(oldValue);
}
}
Tail.EmitRead(ctx, null);
// note we demanded always returns a value
if (Helpers.IsValueType(expectedType))
{
ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
}
ctx.StoreValue(oldValue);
ctx.Branch(next, false);
// outro
ctx.MarkLabel(end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadValue(oldValue); // load the old value
}
}
示例3: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
ctx.LoadValue((int)fieldNumber);
ctx.LoadValue((int)wireType);
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoWriter).GetMethod("WriteFieldHeader"));
Tail.EmitWrite(ctx, valueFrom);
}
示例4: 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"));
}
示例5: 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);
}
示例6:
void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
if (overwriteList)
{
ctx.LoadNullRef();
}
else
{
ctx.LoadValue(valueFrom);
}
ctx.LoadReaderWriter();
ctx.EmitCall(typeof(ProtoReader).GetMethod("AppendBytes"));
}
示例7: 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);
}
示例8: EmitDedicatedMethod
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 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 (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;
#endif
}
示例9: 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
}
}
}
}
示例10: 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);
//.........这里部分代码省略.........
示例11: EmitWrite
protected override void EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using(Compiler.Local valOrNull = ctx.GetLocalWithValue(expectedType, valueFrom))
using(Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
{
ctx.LoadNullRef();
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(valOrNull, expectedType);
ctx.LoadValue(expectedType.GetProperty("HasValue"));
}
else
{
ctx.LoadValue(valOrNull);
}
Compiler.CodeLabel @end = ctx.DefineLabel();
ctx.BranchIfFalse(@end, false);
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(valOrNull, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(valOrNull);
}
Tail.EmitWrite(ctx, null);
ctx.MarkLabel(@end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("EndSubItem"));
}
}
示例12:
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"));
}
}
示例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);
}
示例14: 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);
}
}
}
示例15:
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);
}
}