本文整理汇总了C#中Lens.Compiler.Context.WrapDelegate方法的典型用法代码示例。如果您正苦于以下问题:C# Context.WrapDelegate方法的具体用法?C# Context.WrapDelegate怎么用?C# Context.WrapDelegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lens.Compiler.Context
的用法示例。
在下文中一共展示了Context.WrapDelegate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessClosures
public override void ProcessClosures(Context ctx)
{
if(LeftOperand is LambdaNode)
LeftOperand.ProcessClosures(ctx);
if (RightOperand is LambdaNode)
RightOperand.ProcessClosures(ctx);
var leftType = LeftOperand.GetExpressionType(ctx);
var rightGetter = RightOperand as GetMemberNode;
if (!IsLeft && leftType.IsCallableType() && rightGetter != null)
{
if (rightGetter.TypeHints.IsEmpty())
{
var returnType = ctx.ResolveMethod(leftType, "Invoke").ReturnType;
rightGetter.TypeHints = new List<TypeSignature> {TypeSignature.Parse(returnType.FullName)};
}
}
var rightType = RightOperand.GetExpressionType(ctx);
if (rightGetter != null)
rightGetter.TypeHints.Clear();
if (!IsLeft && leftType.IsCallableType() && rightType.IsCallableType())
{
if (!ctx.CanCombineDelegates(leftType, rightType))
Error(Translations.CompilerMessages.DelegatesNotCombinable, leftType, rightType);
var argTypes = ctx.WrapDelegate(leftType).ArgumentTypes;
var argGetters = argTypes.Select((a, id) => Expr.GetArg(id)).Cast<NodeBase>().ToArray();
if (LeftOperand is GetMemberNode)
(LeftOperand as GetMemberNode).TypeHints.Clear();
_Method = ctx.CurrentScope.CreateClosureMethod(ctx, argTypes, ctx.WrapDelegate(rightType).ReturnType);
_Method.Body =
Expr.Block(
Expr.Invoke(
RightOperand,
Expr.Invoke(
LeftOperand,
argGetters
)
)
);
var methodBackup = ctx.CurrentMethod;
ctx.CurrentMethod = _Method;
var scope = _Method.Scope;
scope.InitializeScope(ctx);
_Method.Body.ProcessClosures(ctx);
_Method.PrepareSelf();
scope.FinalizeScope(ctx);
ctx.CurrentMethod = methodBackup;
}
}