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


C# IILGen.Callvirt方法代码示例

本文整理汇总了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);
 }
开发者ID:yonglehou,项目名称:BTDB,代码行数:40,代码来源:ListTypeDescriptor.cs

示例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);
 }
开发者ID:Bobris,项目名称:BTDB,代码行数:42,代码来源:DictionaryTypeDescriptor.cs

示例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);
     }
 }
开发者ID:klesta490,项目名称:BTDB,代码行数:68,代码来源:ObjectTypeDescriptor.cs


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