本文整理汇总了C#中IILGen.DeclareLocal方法的典型用法代码示例。如果您正苦于以下问题:C# IILGen.DeclareLocal方法的具体用法?C# IILGen.DeclareLocal怎么用?C# IILGen.DeclareLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IILGen
的用法示例。
在下文中一共展示了IILGen.DeclareLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public void Load(IILGen ilGenerator, Action<IILGen> pushReaderOrCtx)
{
var localCount = ilGenerator.DeclareLocal(typeof(uint));
var localResultOfObject = ilGenerator.DeclareLocal(typeof(object));
var localResult = ilGenerator.DeclareLocal(HandledType());
var loadSkipped = ilGenerator.DefineLabel();
var finish = ilGenerator.DefineLabel();
var readfinish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
var genericArguments = _type.GetGenericArguments();
object fake;
ilGenerator
.Do(pushReaderOrCtx)
.Ldloca(localResultOfObject)
.Callvirt(() => default(IReaderCtx).ReadObject(out fake))
.Brfalse(loadSkipped)
.Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
.Stloc(localCount)
.Ldloc(localCount)
.Newobj(typeof(Dictionary<,>).MakeGenericType(genericArguments).GetConstructor(new[] { typeof(int) }))
.Stloc(localResult)
.Do(pushReaderOrCtx)
.Ldloc(localResult)
.Castclass(typeof(object))
.Callvirt(() => default(IReaderCtx).RegisterObject(null))
.Mark(next)
.Ldloc(localCount)
.Brfalse(readfinish)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.ConvU4()
.Stloc(localCount)
.Ldloc(localResult)
.GenerateLoad(_keysHandler, genericArguments[0], pushReaderOrCtx, _typeConvertorGenerator)
.GenerateLoad(_valuesHandler, genericArguments[1], pushReaderOrCtx, _typeConvertorGenerator)
.Callvirt(_type.GetMethod("Add"))
.Br(next)
.Mark(readfinish)
.Do(pushReaderOrCtx)
.Callvirt(() => default(IReaderCtx).ReadObjectDone())
.Br(finish)
.Mark(loadSkipped)
.Ldloc(localResultOfObject)
.Isinst(_type)
.Stloc(localResult)
.Mark(finish)
.Ldloc(localResult);
}
示例2: FreeContent
public bool FreeContent(IILGen ilGenerator, Action<IILGen> pushReaderOrCtx)
{
var needsFreeContent = false;
var localCount = ilGenerator.DeclareLocal(typeof(uint));
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Do(pushReaderOrCtx)
.Callvirt(() => ((IReaderCtx)null).SkipObject())
.Brfalse(finish)
.Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
.Callvirt(() => ((AbstractBufferedReader)null).ReadVUInt32())
.Stloc(localCount)
.Mark(next)
.Ldloc(localCount)
.Brfalse(finish)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.ConvU4()
.Stloc(localCount)
.GenerateFreeContent(_keysHandler, pushReaderOrCtx, ref needsFreeContent)
.GenerateFreeContent(_valuesHandler, pushReaderOrCtx, ref needsFreeContent)
.Br(next)
.Mark(finish);
return needsFreeContent;
}
示例3: GenerateSkip
public void GenerateSkip(IILGen ilGenerator, Action<IILGen> pushReader, Action<IILGen> pushCtx)
{
var localCount = ilGenerator.DeclareLocal(typeof(uint));
var skipFinished = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Do(pushReader)
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
.Stloc(localCount)
.Ldloc(localCount)
.Brfalse(skipFinished)
.Mark(next)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.Stloc(localCount)
.Ldloc(localCount)
.Brfalse(skipFinished);
_keyDescriptor.GenerateSkipEx(ilGenerator, pushReader, pushCtx);
_valueDescriptor.GenerateSkipEx(ilGenerator, pushReader, pushCtx);
ilGenerator
.Br(next)
.Mark(skipFinished);
}
示例4: GenerateSave
public void GenerateSave(IILGen ilGenerator, Action<IILGen> pushWriter, Action<IILGen> pushCtx,
Action<IILGen> pushValue, Type saveType)
{
var notnull = ilGenerator.DefineLabel();
var completeFinish = ilGenerator.DefineLabel();
var notDictionary = ilGenerator.DefineLabel();
var keyType = saveType.GetGenericArguments()[0];
var valueType = saveType.GetGenericArguments()[1];
var typeAsIDictionary = typeof(IDictionary<,>).MakeGenericType(keyType, valueType);
var typeAsICollection = typeAsIDictionary.GetInterface("ICollection`1");
var localDict = ilGenerator.DeclareLocal(typeAsIDictionary);
ilGenerator
.Do(pushValue)
.Castclass(typeAsIDictionary)
.Stloc(localDict)
.Ldloc(localDict)
.Brtrue(notnull)
.Do(pushWriter)
.Callvirt(() => default(AbstractBufferedWriter).WriteByteZero())
.Br(completeFinish)
.Mark(notnull)
.Do(pushWriter)
.Ldloc(localDict)
.Callvirt(typeAsICollection.GetProperty("Count").GetGetMethod())
.LdcI4(1)
.Add()
.Callvirt(() => default(AbstractBufferedWriter).WriteVUInt32(0));
{
var typeAsDictionary = typeof(Dictionary<,>).MakeGenericType(keyType, valueType);
var getEnumeratorMethod = typeAsDictionary.GetMethods()
.Single(m => m.Name == "GetEnumerator" && m.ReturnType.IsValueType && m.GetParameters().Length == 0);
var typeAsIEnumerator = getEnumeratorMethod.ReturnType;
var currentGetter = typeAsIEnumerator.GetProperty("Current").GetGetMethod();
var typeKeyValuePair = currentGetter.ReturnType;
var localEnumerator = ilGenerator.DeclareLocal(typeAsIEnumerator);
var localPair = ilGenerator.DeclareLocal(typeKeyValuePair);
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Ldloc(localDict)
.Castclass(typeAsDictionary)
.Brfalse(notDictionary)
.Ldloc(localDict)
.Castclass(typeAsDictionary)
.Callvirt(getEnumeratorMethod)
.Stloc(localEnumerator)
.Try()
.Mark(next)
.Ldloca(localEnumerator)
.Call(typeAsIEnumerator.GetMethod("MoveNext"))
.Brfalse(finish)
.Ldloca(localEnumerator)
.Call(currentGetter)
.Stloc(localPair);
_keyDescriptor.GenerateSaveEx(ilGenerator, pushWriter, pushCtx,
il => il.Ldloca(localPair).Call(typeKeyValuePair.GetProperty("Key").GetGetMethod()), keyType);
_valueDescriptor.GenerateSaveEx(ilGenerator, pushWriter, pushCtx,
il => il.Ldloca(localPair).Call(typeKeyValuePair.GetProperty("Value").GetGetMethod()), valueType);
ilGenerator
.Br(next)
.Mark(finish)
.Finally()
.Ldloca(localEnumerator)
.Constrained(typeAsIEnumerator)
.Callvirt(() => default(IDisposable).Dispose())
.EndTry()
.Br(completeFinish);
}
{
var getEnumeratorMethod = typeAsIDictionary.GetInterface("IEnumerable`1").GetMethod("GetEnumerator");
var typeAsIEnumerator = getEnumeratorMethod.ReturnType;
var currentGetter = typeAsIEnumerator.GetProperty("Current").GetGetMethod();
var typeKeyValuePair = currentGetter.ReturnType;
var localEnumerator = ilGenerator.DeclareLocal(typeAsIEnumerator);
var localPair = ilGenerator.DeclareLocal(typeKeyValuePair);
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Mark(notDictionary)
.Ldloc(localDict)
.Callvirt(getEnumeratorMethod)
.Stloc(localEnumerator)
.Try()
.Mark(next)
.Ldloc(localEnumerator)
.Callvirt(() => default(IEnumerator).MoveNext())
.Brfalse(finish)
.Ldloc(localEnumerator)
.Callvirt(currentGetter)
.Stloc(localPair);
_keyDescriptor.GenerateSaveEx(ilGenerator, pushWriter, pushCtx, il => il.Ldloca(localPair).Call(typeKeyValuePair.GetProperty("Key").GetGetMethod()), keyType);
_valueDescriptor.GenerateSaveEx(ilGenerator, pushWriter, pushCtx, il => il.Ldloca(localPair).Call(typeKeyValuePair.GetProperty("Value").GetGetMethod()), valueType);
ilGenerator
.Br(next)
.Mark(finish)
.Finally()
.Ldloc(localEnumerator)
.Callvirt(() => default(IDisposable).Dispose())
.EndTry()
.Mark(completeFinish);
//.........这里部分代码省略.........
示例5: 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);
}
示例6: GenerateTypeIterator
public void GenerateTypeIterator(IILGen ilGenerator, Action<IILGen> pushObj, Action<IILGen> pushCtx)
{
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
var itemType = _listTypeDescriptor._typeSerializers.LoadAsType(_listTypeDescriptor._itemDescriptor);
var localList = ilGenerator.DeclareLocal(typeof(IList<>).MakeGenericType(itemType));
var localIndex = ilGenerator.DeclareLocal(typeof(int));
var localCount = ilGenerator.DeclareLocal(typeof(int));
ilGenerator
.Do(pushObj)
.Castclass(localList.LocalType)
.Dup()
.Stloc(localList)
.Callvirt(localList.LocalType.GetInterface("ICollection`1").GetProperty("Count").GetGetMethod())
.Stloc(localCount)
.LdcI4(0)
.Stloc(localIndex)
.Mark(next)
.Ldloc(localIndex)
.Ldloc(localCount)
.BgeUn(finish)
.Do(pushCtx)
.Ldloc(localList)
.Ldloc(localIndex)
.Callvirt(localList.LocalType.GetMethod("get_Item"))
.Callvirt(() => default(IDescriptorSerializerLiteContext).StoreNewDescriptors(null))
.Ldloc(localIndex)
.LdcI4(1)
.Add()
.Stloc(localIndex)
.Br(next)
.Mark(finish);
}
示例7: GenerateSave
public void GenerateSave(IILGen ilGenerator, Action<IILGen> pushWriter, Action<IILGen> pushCtx, Action<IILGen> pushValue, Type valueType)
{
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
var notnull = ilGenerator.DefineLabel();
var itemType = GetItemType(valueType);
var localList = ilGenerator.DeclareLocal(
typeof(IList<>).MakeGenericType(itemType));
var localIndex = ilGenerator.DeclareLocal(typeof(int));
var localCount = ilGenerator.DeclareLocal(typeof(int));
ilGenerator
.Do(pushValue)
.Castclass(localList.LocalType)
.Dup()
.Stloc(localList)
.BrtrueS(notnull)
.Do(pushWriter)
.LdcI4(0)
.Callvirt(() => default(AbstractBufferedWriter).WriteVUInt32(0))
.Br(finish)
.Mark(notnull)
.Ldloc(localList)
.Callvirt(localList.LocalType.GetInterface("ICollection`1").GetProperty("Count").GetGetMethod())
.Stloc(localCount)
.Do(pushWriter)
.Ldloc(localCount)
.LdcI4(1)
.Add()
.ConvU4()
.Callvirt(() => default(AbstractBufferedWriter).WriteVUInt32(0))
.LdcI4(0)
.Stloc(localIndex)
.Mark(next)
.Ldloc(localIndex)
.Ldloc(localCount)
.BgeUn(finish);
_itemDescriptor.GenerateSaveEx(ilGenerator, pushWriter, pushCtx,
il => il.Ldloc(localList)
.Ldloc(localIndex)
.Callvirt(localList.LocalType.GetMethod("get_Item")), itemType);
ilGenerator
.Ldloc(localIndex)
.LdcI4(1)
.Add()
.Stloc(localIndex)
.Br(next)
.Mark(finish);
}
示例8: 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);
}
示例9: Save
public void Save(IILGen ilGenerator, Action<IILGen> pushWriterOrCtx, Action<IILGen> pushValue)
{
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
var localValue = ilGenerator.DeclareLocal(_type);
var localIndex = ilGenerator.DeclareLocal(typeof(int));
var localCount = ilGenerator.DeclareLocal(typeof(int));
ilGenerator
.Do(pushValue)
.Stloc(localValue)
.Do(pushWriterOrCtx)
.Ldloc(localValue)
.Castclass(typeof(object))
.Callvirt(() => default(IWriterCtx).WriteObject(null))
.Brfalse(finish)
.Ldloc(localValue)
.Callvirt(_type.GetInterface("ICollection`1").GetProperty("Count").GetGetMethod())
.Stloc(localCount)
.Do(Extensions.PushWriterFromCtx(pushWriterOrCtx))
.Ldloc(localCount)
.ConvU4()
.Callvirt(() => default(AbstractBufferedWriter).WriteVUInt32(0))
.Mark(next)
.Ldloc(localIndex)
.Ldloc(localCount)
.BgeUn(finish);
_itemsHandler.Save(ilGenerator, Extensions.PushWriterOrCtxAsNeeded(pushWriterOrCtx, _itemsHandler.NeedsCtx()), il => il
.Ldloc(localValue)
.Ldloc(localIndex)
.Callvirt(_type.GetMethod("get_Item"))
.Do(_typeConvertorGenerator.GenerateConversion(_type.GetGenericArguments()[0], _itemsHandler.HandledType())));
ilGenerator
.Ldloc(localIndex)
.LdcI4(1)
.Add()
.Stloc(localIndex)
.Br(next)
.Mark(finish);
}
示例10: Save
public void Save(IILGen ilGenerator, Action<IILGen> pushWriterOrCtx, Action<IILGen> pushValue)
{
var realfinish = ilGenerator.DefineLabel();
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
var localValue = ilGenerator.DeclareLocal(_type);
var typeAsICollection = _type.GetInterface("ICollection`1");
var typeAsIEnumerable = _type.GetInterface("IEnumerable`1");
var getEnumeratorMethod = typeAsIEnumerable.GetMethod("GetEnumerator");
var typeAsIEnumerator = getEnumeratorMethod.ReturnType;
var typeKeyValuePair = typeAsICollection.GetGenericArguments()[0];
var localEnumerator = ilGenerator.DeclareLocal(typeAsIEnumerator);
var localPair = ilGenerator.DeclareLocal(typeKeyValuePair);
ilGenerator
.Do(pushValue)
.Stloc(localValue)
.Do(pushWriterOrCtx)
.Ldloc(localValue)
.Castclass(typeof(object))
.Callvirt(() => default(IWriterCtx).WriteObject(null))
.Brfalse(realfinish)
.Do(Extensions.PushWriterFromCtx(pushWriterOrCtx))
.Ldloc(localValue)
.Callvirt(typeAsICollection.GetProperty("Count").GetGetMethod())
.ConvU4()
.Callvirt(() => default(AbstractBufferedWriter).WriteVUInt32(0))
.Ldloc(localValue)
.Callvirt(getEnumeratorMethod)
.Stloc(localEnumerator)
.Try()
.Mark(next)
.Ldloc(localEnumerator)
.Callvirt(() => default(IEnumerator).MoveNext())
.Brfalse(finish)
.Ldloc(localEnumerator)
.Callvirt(typeAsIEnumerator.GetProperty("Current").GetGetMethod())
.Stloc(localPair);
_keysHandler.Save(ilGenerator, Extensions.PushWriterOrCtxAsNeeded(pushWriterOrCtx, _keysHandler.NeedsCtx()), il => il
.Ldloca(localPair)
.Call(typeKeyValuePair.GetProperty("Key").GetGetMethod())
.Do(_typeConvertorGenerator.GenerateConversion(_type.GetGenericArguments()[0], _keysHandler.HandledType())));
_valuesHandler.Save(ilGenerator, Extensions.PushWriterOrCtxAsNeeded(pushWriterOrCtx, _valuesHandler.NeedsCtx()), il => il
.Ldloca(localPair)
.Call(typeKeyValuePair.GetProperty("Value").GetGetMethod())
.Do(_typeConvertorGenerator.GenerateConversion(_type.GetGenericArguments()[1], _valuesHandler.HandledType())));
ilGenerator
.Br(next)
.Mark(finish)
.Finally()
.Ldloc(localEnumerator)
.Callvirt(() => default(IDisposable).Dispose())
.EndTry()
.Mark(realfinish);
}
示例11: GenerateSave
public void GenerateSave(IILGen ilGenerator, Action<IILGen> pushWriter, Action<IILGen> pushCtx, Action<IILGen> pushValue, Type valueType)
{
if (GetPreferedType() != valueType)
throw new ArgumentException("value type does not match my type");
var locValue = ilGenerator.DeclareLocal(_type, "value");
ilGenerator
.Do(pushValue)
.Stloc(locValue);
foreach (var pairi in _fields)
{
var pair = pairi;
var methodInfo = _type.GetProperties().First(p => GetPersitentName(p) == pair.Key).GetGetMethod();
pair.Value.GenerateSaveEx(ilGenerator, pushWriter, pushCtx, il => il.Ldloc(locValue).Callvirt(methodInfo), methodInfo.ReturnType);
}
}
示例12: 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);
}
}
示例13: FreeContent
public bool FreeContent(IILGen ilGenerator, Action<IILGen> pushReaderOrCtx)
{
var fakeMethod = ILBuilder.Instance.NewMethod<Action>("Relation_fake");
var fakeGenerator = fakeMethod.Generator;
if (_keysHandler.FreeContent(fakeGenerator, _ => { }))
throw new BTDBException("Not supported IDictionary in IDictionary key");
var containsNestedIDictionaries = _valuesHandler.FreeContent(fakeGenerator, _ => { });
if (!containsNestedIDictionaries)
{
ilGenerator
.Do(pushReaderOrCtx)
.Castclass(typeof(IDBReaderCtx))
.Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt64())
.Callvirt(() => default(IDBReaderCtx).RegisterDict(0ul));
}
else
{
var genericArguments = _type.GetGenericArguments();
var instanceType = typeof(ODBDictionary<,>).MakeGenericType(genericArguments);
var dictId = ilGenerator.DeclareLocal(typeof(ulong));
ilGenerator
.Do(pushReaderOrCtx)
.Castclass(typeof(IDBReaderCtx))
.Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt64())
.Stloc(dictId)
.Ldloc(dictId)
.Callvirt(() => default(IDBReaderCtx).RegisterDict(0ul))
.Do(pushReaderOrCtx)
.Ldloc(dictId)
.LdcI4(_configurationId)
//ODBDictionary.DoFreeContent(IReaderCtx ctx, ulong id, int cfgId)
.Call(instanceType.GetMethod("DoFreeContent"));
}
return true;
}
示例14: Skip
public void Skip(IILGen ilGenerator, Action<IILGen> pushReaderOrCtx)
{
var localCount = ilGenerator.DeclareLocal(typeof(uint));
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
ilGenerator
.Do(pushReaderOrCtx)
.Callvirt(() => default(IReaderCtx).SkipObject())
.Brfalse(finish)
.Do(Extensions.PushReaderFromCtx(pushReaderOrCtx))
.Callvirt(() => default(AbstractBufferedReader).ReadVUInt32())
.Stloc(localCount)
.Mark(next)
.Ldloc(localCount)
.Brfalse(finish)
.Ldloc(localCount)
.LdcI4(1)
.Sub()
.ConvU4()
.Stloc(localCount)
.GenerateSkip(_itemsHandler, pushReaderOrCtx)
.Br(next)
.Mark(finish);
}
示例15: GenerateTypeIterator
public void GenerateTypeIterator(IILGen ilGenerator, Action<IILGen> pushObj, Action<IILGen> pushCtx, Type type)
{
var finish = ilGenerator.DefineLabel();
var next = ilGenerator.DefineLabel();
var keyType = _owner._typeSerializers.LoadAsType(_owner._keyDescriptor);
var valueType = _owner._typeSerializers.LoadAsType(_owner._valueDescriptor);
if (_owner._type == null) _owner._type = type;
var isDict = _owner._type != null && _owner._type.GetGenericTypeDefinition() == typeof(Dictionary<,>);
var typeAsIDictionary = isDict ? _owner._type : typeof(IDictionary<,>).MakeGenericType(keyType, valueType);
var getEnumeratorMethod = isDict
? typeAsIDictionary.GetMethods()
.Single(
m => m.Name == "GetEnumerator" && m.ReturnType.IsValueType && m.GetParameters().Length == 0)
: typeAsIDictionary.GetInterface("IEnumerable`1").GetMethod("GetEnumerator");
var typeAsIEnumerator = getEnumeratorMethod.ReturnType;
var currentGetter = typeAsIEnumerator.GetProperty("Current").GetGetMethod();
var typeKeyValuePair = currentGetter.ReturnType;
var localEnumerator = ilGenerator.DeclareLocal(typeAsIEnumerator);
var localPair = ilGenerator.DeclareLocal(typeKeyValuePair);
ilGenerator
.Do(pushObj)
.Castclass(typeAsIDictionary)
.Callvirt(getEnumeratorMethod)
.Stloc(localEnumerator)
.Try()
.Mark(next)
.Do(il =>
{
if (isDict)
{
il
.Ldloca(localEnumerator)
.Call(typeAsIEnumerator.GetMethod("MoveNext"));
}
else
{
il
.Ldloc(localEnumerator)
.Callvirt(() => default(IEnumerator).MoveNext());
}
})
.Brfalse(finish)
.Do(il =>
{
if (isDict)
{
il
.Ldloca(localEnumerator)
.Call(currentGetter);
}
else
{
il
.Ldloc(localEnumerator)
.Callvirt(currentGetter);
}
})
.Stloc(localPair);
if (!_owner._keyDescriptor.Sealed)
{
ilGenerator
.Do(pushCtx)
.Ldloca(localPair)
.Call(typeKeyValuePair.GetProperty("Key").GetGetMethod())
.Callvirt(() => default(IDescriptorSerializerLiteContext).StoreNewDescriptors(null));
}
if (!_owner._valueDescriptor.Sealed)
{
ilGenerator
.Do(pushCtx)
.Ldloca(localPair)
.Call(typeKeyValuePair.GetProperty("Value").GetGetMethod())
.Callvirt(() => default(IDescriptorSerializerLiteContext).StoreNewDescriptors(null));
}
ilGenerator
.Br(next)
.Mark(finish)
.Finally()
.Do(il =>
{
if (isDict)
{
il
.Ldloca(localEnumerator)
.Constrained(typeAsIEnumerator);
}
else
{
il.Ldloc(localEnumerator);
}
})
.Callvirt(() => default(IDisposable).Dispose())
.EndTry();
}