本文整理汇总了C#中IILGen.Callvirt方法的典型用法代码示例。如果您正苦于以下问题:C# IILGen.Callvirt方法的具体用法?C# IILGen.Callvirt怎么用?C# IILGen.Callvirt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IILGen
的用法示例。
在下文中一共展示了IILGen.Callvirt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateLoad
public void GenerateLoad(IILGen ilGenerator, Action<IILGen> pushReader, Action<IILGen> pushCtx, Action<IILGen> pushDescriptor, Type targetType)
{
var localCount = ilGenerator.DeclareLocal(typeof(int));
var itemType = _typeSerializers.LoadAsType(_itemDescriptor);
var listType = typeof(ListWithDescriptor<>).MakeGenericType(itemType);
if (!targetType.IsAssignableFrom(listType)) throw new NotSupportedException();
var localList = ilGenerator.DeclareLocal(listType);
var loadFinished = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Do(pushReader)
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
.ConvI4()
.Dup()
.Stloc(localCount)
.Brfalse(loadFinished)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.Dup()
.Stloc(localCount)
.Do(pushDescriptor)
.Newobj(listType.GetConstructor(new[] { typeof(int), typeof(ITypeDescriptor) }))
.Stloc(localList)
.Mark(next)
.Ldloc(localCount)
.Brfalse(loadFinished)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.Stloc(localCount)
.Ldloc(localList);
_itemDescriptor.GenerateLoadEx(ilGenerator, pushReader, pushCtx, il => il.Do(pushDescriptor).LdcI4(0).Callvirt(() => default(ITypeDescriptor).NestedType(0)), itemType);
ilGenerator
.Callvirt(listType.GetInterface("ICollection`1").GetMethod("Add"))
.Br(next)
.Mark(loadFinished)
.Ldloc(localList)
.Castclass(targetType);
}
示例2: GenerateLoad
public void GenerateLoad(IILGen ilGenerator, Action<IILGen> pushReader, Action<IILGen> pushCtx, Action<IILGen> pushDescriptor, Type targetType)
{
var localCount = ilGenerator.DeclareLocal(typeof(int));
var targetIDictionary = targetType.GetInterface("IDictionary`2") ?? targetType;
var targetTypeArguments = targetIDictionary.GetGenericArguments();
var keyType = _typeSerializers.LoadAsType(_keyDescriptor, targetTypeArguments[0]);
var valueType = _typeSerializers.LoadAsType(_valueDescriptor, targetTypeArguments[1]);
var dictionaryType = typeof(DictionaryWithDescriptor<,>).MakeGenericType(keyType, valueType);
if (!targetType.IsAssignableFrom(dictionaryType)) throw new InvalidOperationException();
var localDict = ilGenerator.DeclareLocal(dictionaryType);
var loadFinished = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Do(pushReader)
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
.ConvI4()
.Dup()
.LdcI4(1)
.Sub()
.Stloc(localCount)
.Brfalse(loadFinished)
.Ldloc(localCount)
.Do(pushDescriptor)
.Newobj(dictionaryType.GetConstructor(new[] { typeof(int), typeof(ITypeDescriptor) }))
.Stloc(localDict)
.Mark(next)
.Ldloc(localCount)
.Brfalse(loadFinished)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.Stloc(localCount)
.Ldloc(localDict);
_keyDescriptor.GenerateLoadEx(ilGenerator, pushReader, pushCtx, il => il.Do(pushDescriptor).LdcI4(0).Callvirt(() => default(ITypeDescriptor).NestedType(0)), keyType, _convertorGenerator);
_valueDescriptor.GenerateLoadEx(ilGenerator, pushReader, pushCtx, il => il.Do(pushDescriptor).LdcI4(1).Callvirt(() => default(ITypeDescriptor).NestedType(0)), valueType, _convertorGenerator);
ilGenerator
.Callvirt(dictionaryType.GetMethod("Add"))
.Br(next)
.Mark(loadFinished)
.Ldloc(localDict)
.Castclass(targetType);
}
示例3: GenerateLoad
public void GenerateLoad(IILGen ilGenerator, Action<IILGen> pushReader, Action<IILGen> pushCtx, Action<IILGen> pushDescriptor, Type targetType)
{
if (targetType == typeof(object))
{
var resultLoc = ilGenerator.DeclareLocal(typeof(DynamicObject), "result");
var labelNoCtx = ilGenerator.DefineLabel();
ilGenerator
.Do(pushDescriptor)
.Castclass(typeof(ObjectTypeDescriptor))
.Newobj(typeof(DynamicObject).GetConstructor(new[] { typeof(ObjectTypeDescriptor) }))
.Stloc(resultLoc)
.Do(pushCtx)
.BrfalseS(labelNoCtx)
.Do(pushCtx)
.Ldloc(resultLoc)
.Callvirt(() => default(ITypeBinaryDeserializerContext).AddBackRef(null))
.Mark(labelNoCtx);
var idx = 0;
foreach (var pair in _fields)
{
var idxForCapture = idx;
ilGenerator.Ldloc(resultLoc);
ilGenerator.LdcI4(idx);
pair.Value.GenerateLoadEx(ilGenerator, pushReader, pushCtx,
il =>
il.Do(pushDescriptor)
.LdcI4(idxForCapture)
.Callvirt(() => default(ITypeDescriptor).NestedType(0)), typeof(object), _typeSerializers.ConvertorGenerator);
ilGenerator.Callvirt(() => default(DynamicObject).SetFieldByIdxFast(0, null));
idx++;
}
ilGenerator
.Ldloc(resultLoc)
.Castclass(typeof(object));
}
else
{
var resultLoc = ilGenerator.DeclareLocal(targetType, "result");
var labelNoCtx = ilGenerator.DefineLabel();
ilGenerator
.Newobj(targetType.GetConstructor(Type.EmptyTypes))
.Stloc(resultLoc)
.Do(pushCtx)
.BrfalseS(labelNoCtx)
.Do(pushCtx)
.Ldloc(resultLoc)
.Callvirt(() => default(ITypeBinaryDeserializerContext).AddBackRef(null))
.Mark(labelNoCtx);
var props = targetType.GetProperties();
for (var idx = 0; idx < _fields.Count; idx++)
{
var idxForCapture = idx;
var pair = _fields[idx];
var prop = props.FirstOrDefault(p => GetPersitentName(p) == pair.Key);
if (prop == null || !_typeSerializers.IsSafeToLoad(prop.PropertyType))
{
pair.Value.GenerateSkipEx(ilGenerator, pushReader, pushCtx);
continue;
}
ilGenerator.Ldloc(resultLoc);
pair.Value.GenerateLoadEx(ilGenerator, pushReader, pushCtx,
il => il.Do(pushDescriptor).LdcI4(idxForCapture).Callvirt(() => default(ITypeDescriptor).NestedType(0)),
prop.PropertyType, _typeSerializers.ConvertorGenerator);
ilGenerator.Callvirt(prop.GetSetMethod());
}
ilGenerator.Ldloc(resultLoc);
}
}