本文整理汇总了C#中InvocationExpression.ReplaceWith方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpression.ReplaceWith方法的具体用法?C# InvocationExpression.ReplaceWith怎么用?C# InvocationExpression.ReplaceWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvocationExpression
的用法示例。
在下文中一共展示了InvocationExpression.ReplaceWith方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocationExpression
public override void VisitInvocationExpression (InvocationExpression invocationExpression)
{
base.VisitInvocationExpression (invocationExpression);
var hasRefs = invocationExpression.Arguments.OfType<DirectionExpression> ().Any ();
if (hasRefs) {
var args = invocationExpression.Arguments.OfType<DirectionExpression> ().ToList ();
var target = invocationExpression.Target;
var lblock = new BlockStatement {
};
for (int i = 0; i < args.Count; i++) {
var a = args [i];
var vname = "_p" + i;
var va = new VariableDeclarationStatement (AstType.Null, vname, new ArrayCreateExpression {
Initializer = new ArrayInitializerExpression (a.Expression.Clone ())
});
a.ReplaceWith (new IdentifierExpression (vname));
lblock.Add (va);
}
var rname = "_r";
var ra = new VariableDeclarationStatement (AstType.Null, rname, invocationExpression.Clone ());
lblock.Add (ra);
for (int i = 0; i < args.Count; i++) {
var a = args [i];
var vname = "_p" + i;
var va = new AssignmentExpression (a.Expression.Clone (),
new IndexerExpression (
new IdentifierExpression (vname), new PrimitiveExpression (0)));
lblock.Add (va);
}
lblock.Add (new ReturnStatement (new IdentifierExpression (rname)));
var lambda = new LambdaExpression {
Body = lblock,
};
var ilambda = new InvocationExpression (lambda);
invocationExpression.ReplaceWith (ilambda);
}
}
示例2: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpression e)
{
var md = e.Annotation<MethodDefinition>();
if (md != null && (md.IsGetter || md.IsSetter))
{
var p = md.DeclaringType.Properties.FirstOrDefault(x => x.GetMethod == md || x.SetMethod == md);
if (p != null)
{
// 转换为属性访问
var target = (e.Target as MemberReferenceExpression).Target;
if (p.IsIndexer())
{
IndexerExpression ie = new IndexerExpression(target.Detach()).WithAnnotation(p);
e.Arguments.MoveTo(ie.Arguments);
e.ReplaceWith(ie);
}
else
{
//MemberReferenceExpression mre = new MemberReferenceExpression(target.Detach(), p.Name).WithAnnotation(p);
}
}
}
//[CompilerGenerated]
//private sealed class C_e_5
//{
// public Action f_1_E2DC5B04;
// public void M_1_void(object x)
// {
// this.f_1_E2DC5B04();
// }
//}
//
//public ActionCommand(Action execute)
//{
// Action<object> action = null;
// ActionCommand.C_e_5 c_e_ = new ActionCommand.C_e_5();
// c_e_.f_1_E2DC5B04 = execute;
// if (action == null)
// {
// action = new Action<object>(c_e_.M_1_void);
// }
// base..ctor(action);
//}
//
//====>
//public ActionCommand(Action execute) : base(x=>execute())
//{
//}
base.VisitInvocationExpression(e);
}