public IEnumerable<CodeAction> GetActions(RefactoringContext context) { var catchClause = context.GetNode<CatchClause>(); if (catchClause == null) yield break; if (!catchClause.Type.IsNull) yield break; yield return new CodeAction(context.TranslateString("Add type specifier"), script => { var newType = context.CreateShortType("System", "Exception"); var namingHelper = new NamingHelper(context); var newIdentifier = Identifier.Create(namingHelper.GenerateVariableName(newType, "e")); script.Replace(catchClause, new CatchClause { Type = newType, VariableNameToken = newIdentifier, Body = catchClause.Body.Clone() as BlockStatement }); script.Select(newType); }); }
public InitializerConversionVisitor(RefactoringContext context) { this.context = context; namingHelper = new NamingHelper(context); }
static ForeachStatement MakeForeach(Expression node, IType type, RefactoringContext context) { var namingHelper = new NamingHelper(context); return new ForeachStatement { VariableType = new SimpleType("var"), VariableName = namingHelper.GenerateVariableName(type), InExpression = node.Clone(), EmbeddedStatement = new BlockStatement() }; }