本文整理汇总了C#中EditorContext.GetContainingElement方法的典型用法代码示例。如果您正苦于以下问题:C# EditorContext.GetContainingElement方法的具体用法?C# EditorContext.GetContainingElement怎么用?C# EditorContext.GetContainingElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EditorContext
的用法示例。
在下文中一共展示了EditorContext.GetContainingElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetElement
protected AbstractNode GetElement(EditorContext context)
{
// a = Foo() : AssignmentExpression.Left == IdentifierExpression(*identifier*)
// var a = Foo() : VariableDeclaration(*name*).Initializer != empty
var assignment = context.GetContainingElement<AssignmentExpression>();
if (assignment != null)
return assignment;
var declaration = context.GetContainingElement<LocalVariableDeclaration>();
if (declaration != null)
return declaration;
return null;
}
示例2: GetVariableName
protected string GetVariableName(EditorContext context)
{
// a = Foo() : AssignmentExpression.Left == IdentifierExpression(*identifier*)
// var a = Foo() : VariableDeclaration(*name*).Initializer != empty
var variableName = GetVariableNameFromAssignment(context.GetContainingElement<AssignmentExpression>());
if (variableName != null)
return variableName;
variableName = GetVariableNameFromVariableDeclaration(context.GetContainingElement<LocalVariableDeclaration>());
if (variableName != null)
return variableName;
return null;
}
示例3: GetStatementRegion
protected DomRegion GetStatementRegion(EditorContext context)
{
// a = Foo() : AssignmentExpression.Left == IdentifierExpression(*identifier*)
// var a = Foo() : VariableDeclaration(*name*).Initializer != empty
var assignment = context.GetContainingElement<AssignmentExpression>();
if (assignment != null)
return DomRegion.FromLocation(assignment.StartLocation, assignment.EndLocation);
var declaration = context.GetContainingElement<LocalVariableDeclaration>();
if (declaration != null)
return DomRegion.FromLocation(declaration.StartLocation, declaration.EndLocation);
return DomRegion.Empty;
}
示例4: IsAvailable
public override bool IsAvailable(EditorContext context)
{
this.currentExpr = context.GetContainingElement<Expression>();
if (currentExpr is InvocationExpression) {
// InvocationExpression (e.g. "e.Foo()") has MemberReferenceExpression as TargetObject (e.g. "e.Foo")
// "e.Foo() -> e"
this.targetExpr = GetTarget(((InvocationExpression)currentExpr).TargetObject);
} else {
// "a.b" -> "a"
this.targetExpr = GetTarget(currentExpr);
}
return
this.targetExpr is MemberReferenceExpression ||
this.targetExpr is CastExpression ||
this.targetExpr is ParenthesizedExpression;
//this.targetExpr is IdentifierExpression; // "don't offer the action for just a.b, only for a.b.c"
}
示例5: GetContextAction
/// <summary>
/// If given symbol is Unknown ResolveResult, returns action that can generate code for this missing symbol.
/// </summary>
public static GenerateCodeContextAction GetContextAction(EditorContext context)
{
if (context.CurrentSymbol is UnknownMethodResolveResult) {
UnknownMethodResolveResult unknownMethodCall = (UnknownMethodResolveResult)context.CurrentSymbol;
Ast.Expression expression = context.GetContainingElement<Ast.InvocationExpression>();
if (expression == null)
return null;
string title = "${res:AddIns.SharpRefactoring.IntroduceMethod}";
try {
title = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.IntroduceMethod}"), unknownMethodCall.CallName, unknownMethodCall.Target.FullyQualifiedName);
} catch (FormatException) {
}
if (unknownMethodCall.Target != null && unknownMethodCall.Target.IsUserCode()) {
// Don't introduce method on non-modyfiable types
return new IntroduceMethodContextAction(unknownMethodCall, expression, context.Editor) {
Title = title
};
}
}
return null;
}