本文整理汇总了C#中Mono.CSharp.Expression.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Clone方法的具体用法?C# Expression.Clone怎么用?C# Expression.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.Expression
的用法示例。
在下文中一共展示了Expression.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFromExpression
CodeAction CreateFromExpression(RefactoringContext context, Expression expression)
{
var resolveResult = context.Resolve(expression);
if (resolveResult.IsError)
return null;
return new CodeAction(context.TranslateString("Extract method"), script => {
string methodName = "NewMethod";
var method = new MethodDeclaration {
ReturnType = context.CreateShortType(resolveResult.Type),
Name = methodName,
Body = new BlockStatement {
new ReturnStatement(expression.Clone())
}
};
if (!StaticVisitor.UsesNotStaticMember(context, expression))
method.Modifiers |= Modifiers.Static;
var usedVariables = VariableLookupVisitor.Analyze(context, expression);
var inExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
usedVariables.Sort ((l, r) => l.Region.Begin.CompareTo (r.Region.Begin));
var target = new IdentifierExpression(methodName);
var invocation = new InvocationExpression(target);
foreach (var variable in usedVariables) {
Expression argumentExpression = new IdentifierExpression(variable.Name);
var mod = ParameterModifier.None;
if (inExtractedRegion.GetStatus (variable) == VariableState.Changed) {
mod = ParameterModifier.Ref;
argumentExpression = new DirectionExpression(FieldDirection.Ref, argumentExpression);
}
method.Parameters.Add(new ParameterDeclaration(context.CreateShortType(variable.Type), variable.Name, mod));
invocation.Arguments.Add(argumentExpression);
}
script
.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method)
.ContinueScript (delegate {
script.Replace(expression, invocation);
script.Link(target, method.NameToken);
});
}, expression);
}
示例2: CloneTo
protected override void CloneTo (CloneContext clonectx, Expression t)
{
StackAlloc target = (StackAlloc) t;
target.count = count.Clone (clonectx);
target.t = t.Clone (clonectx);
}