当前位置: 首页>>代码示例>>C#>>正文


C# RefactoringContext.GetSelectedNodes方法代码示例

本文整理汇总了C#中RefactoringContext.GetSelectedNodes方法的典型用法代码示例。如果您正苦于以下问题:C# RefactoringContext.GetSelectedNodes方法的具体用法?C# RefactoringContext.GetSelectedNodes怎么用?C# RefactoringContext.GetSelectedNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RefactoringContext的用法示例。


在下文中一共展示了RefactoringContext.GetSelectedNodes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetActions

		public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			if (!context.IsSomethingSelected)
				yield break;
			var selected = new List<AstNode>(context.GetSelectedNodes());
			if (selected.Count == 0)
				yield break;
			
			if (selected.Count == 1 && selected [0] is Expression) {
				var codeAction = CreateFromExpression(context, (Expression)selected [0]);
				if (codeAction == null)
					yield break;
				yield return codeAction;
			}

			foreach (var node in selected) {
				if (!(node is Statement) && !(node is Comment) && !(node is NewLineNode) && !(node is PreProcessorDirective))
					yield break;
				if (node.DescendantNodesAndSelf().Any(n => n is YieldBreakStatement || n is YieldReturnStatement))
					yield break;
			}
			var action = CreateFromStatements (context, new List<AstNode> (selected));
			if (action != null)
				yield return action;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:25,代码来源:ExtractMethodAction.cs

示例2: GetActions

		public IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			if (!context.IsSomethingSelected)
				yield break;
			var selected = new List<AstNode>(context.GetSelectedNodes());
			if (selected.Count == 0)
				yield break;
			
			if (selected.Count == 1 && selected [0] is Expression) {
				var codeAction = CreateFromExpression(context, (Expression)selected [0]);
				if (codeAction == null)
					yield break;
				yield return codeAction;
			}
			
			foreach (var node in selected) {
				if (!(node is Statement))
					yield break;
			}
			var action = CreateFromStatements (context, new List<Statement> (selected.OfType<Statement> ()));
			if (action != null)
				yield return action;
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:23,代码来源:ExtractMethodAction.cs

示例3: GetActions

		public IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			if (!context.IsSomethingSelected) {
				yield break;
			}
			var selected = new List<AstNode>(context.GetSelectedNodes());
			if (selected.Count != 1 || !(selected [0] is Expression)) {
				yield break;
			}
			var expr = selected [0] as Expression;
			var visitor = new SearchNodeVisitior(expr);
			
			var node = context.GetNode <BlockStatement>();
			if (node != null) {
				node.AcceptVisitor(visitor);
			}

			yield return new CodeAction(context.TranslateString("Declare local variable"), script => {
				var resolveResult = context.Resolve(expr);
				var guessedType = resolveResult.Type;
				if (resolveResult is MethodGroupResolveResult) {
					guessedType = GetDelegateType(context, ((MethodGroupResolveResult)resolveResult).Methods.First(), expr);
				}
				var name = CreateMethodDeclarationAction.CreateBaseName(expr, guessedType);
				var type = context.UseExplicitTypes ? context.CreateShortType(guessedType) : new SimpleType("var");
				var varDecl = new VariableDeclarationStatement(type, name, expr.Clone());
				if (expr.Parent is ExpressionStatement) {
					script.Replace(expr.Parent, varDecl);
					script.Select(varDecl.Variables.First().NameToken);
				} else {
					var containing = expr.Parent;
					while (!(containing.Parent is BlockStatement)) {
						containing = containing.Parent;
					}

					script.InsertBefore(containing, varDecl);
					var identifierExpression = new IdentifierExpression(name);
					script.Replace(expr, identifierExpression);
					script.Link(varDecl.Variables.First().NameToken, identifierExpression);
				}
			});

			if (visitor.Matches.Count > 1) {
				yield return new CodeAction(string.Format(context.TranslateString("Declare local variable (replace '{0}' occurrences)"), visitor.Matches.Count), script => {
					var resolveResult = context.Resolve(expr);
					var guessedType = resolveResult.Type;
					if (resolveResult is MethodGroupResolveResult) {
						guessedType = GetDelegateType(context, ((MethodGroupResolveResult)resolveResult).Methods.First(), expr);
					}
					var linkedNodes = new List<AstNode>();
					var name = CreateMethodDeclarationAction.CreateBaseName(expr, guessedType);
					var type = context.UseExplicitTypes ? context.CreateShortType(guessedType) : new SimpleType("var");
					var varDecl = new VariableDeclarationStatement(type, name, expr.Clone());
					linkedNodes.Add(varDecl.Variables.First().NameToken);
					var first = visitor.Matches [0];
					if (first.Parent is ExpressionStatement) {
						script.Replace(first.Parent, varDecl);
					} else {
						var containing = first.Parent;
						while (!(containing.Parent is BlockStatement)) {
							containing = containing.Parent;
						}

						script.InsertBefore(containing, varDecl);
						var identifierExpression = new IdentifierExpression(name);
						linkedNodes.Add(identifierExpression);
						script.Replace(first, identifierExpression);
					}
					for (int i = 1; i < visitor.Matches.Count; i++) {
						var identifierExpression = new IdentifierExpression(name);
						linkedNodes.Add(identifierExpression);
						script.Replace(visitor.Matches [i], identifierExpression);
					}
					script.Link(linkedNodes.ToArray ());
				});
			}
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:77,代码来源:DeclareLocalVariableAction.cs


注:本文中的RefactoringContext.GetSelectedNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。