本文整理汇总了C#中ITypeDescriptor.AnyOpNeedsCtx方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDescriptor.AnyOpNeedsCtx方法的具体用法?C# ITypeDescriptor.AnyOpNeedsCtx怎么用?C# ITypeDescriptor.AnyOpNeedsCtx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeDescriptor
的用法示例。
在下文中一共展示了ITypeDescriptor.AnyOpNeedsCtx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewSimpleSaver
Action<AbstractBufferedWriter, object> NewSimpleSaver(ITypeDescriptor descriptor)
{
if (descriptor.AnyOpNeedsCtx()) return null;
var method = ILBuilder.Instance.NewMethod<Action<AbstractBufferedWriter, object>>(descriptor.Name + "SimpleSaver");
var il = method.Generator;
descriptor.GenerateSave(il, ilgen => ilgen.Ldarg(0), null, ilgen =>
{
ilgen.Ldarg(1);
var type = descriptor.GetPreferedType();
if (type != typeof(object))
{
ilgen.UnboxAny(type);
}
}, descriptor.GetPreferedType());
il.Ret();
return method.Create();
}
示例2: LoaderFactory
Func<AbstractBufferedReader, ITypeBinaryDeserializerContext, ITypeSerializersId2LoaderMapping, ITypeDescriptor, object> LoaderFactory(ITypeDescriptor descriptor)
{
var loadAsType = LoadAsType(descriptor);
var methodBuilder = ILBuilder.Instance.NewMethod<Func<AbstractBufferedReader, ITypeBinaryDeserializerContext, ITypeSerializersId2LoaderMapping, ITypeDescriptor, object>>("DeserializerFor" + descriptor.Name);
var il = methodBuilder.Generator;
if (descriptor.AnyOpNeedsCtx())
{
var localCtx = il.DeclareLocal(typeof(ITypeBinaryDeserializerContext), "ctx");
var haveCtx = il.DefineLabel();
il
.Ldarg(1)
.Dup()
.Stloc(localCtx)
.Brtrue(haveCtx)
.Ldarg(0)
.Ldarg(2)
.Newobj(() => new DeserializerCtx(null, null))
.Castclass(typeof(ITypeBinaryDeserializerContext))
.Stloc(localCtx)
.Mark(haveCtx);
descriptor.GenerateLoad(il, ilGen => ilGen.Ldarg(0), ilGen => ilGen.Ldloc(localCtx), ilGen => ilGen.Ldarg(3), loadAsType);
}
else
{
descriptor.GenerateLoad(il, ilGen => ilGen.Ldarg(0), ilGen => ilGen.Ldarg(1), ilGen => ilGen.Ldarg(3), loadAsType);
}
if (loadAsType.IsValueType)
{
il.Box(loadAsType);
}
else if (loadAsType != typeof(object))
{
il.Castclass(typeof(object));
}
il.Ret();
return methodBuilder.Create();
}