CodeAction HandleExpressionStatement(RefactoringContext context, ExpressionStatement expressionStatement) { var expression = expressionStatement.Expression as AssignmentExpression; if (expression == null || expression.Operator != AssignmentOperatorType.Assign) { return(null); } if (!(expression.Right is ObjectCreateExpression)) { return(null); } var expressionResolveResult = context.Resolve(expression.Left); if (!(expressionResolveResult is LocalResolveResult) && !(expressionResolveResult is MemberResolveResult)) { return(null); } IList <AstNode> statements = GetNodes(context.GetNode <Statement>()); var converter = new StatementsToInitializerConverter(context); var newExpression = converter.ConvertToInitializer(expression, ref statements); if (newExpression == null || statements.Count == 0) { return(null); } return(MakeAction(context, expression, newExpression, statements)); }
CodeAction HandleInitializer(RefactoringContext context, VariableInitializer initializer) { var objectCreateExpression = initializer.Initializer as ObjectCreateExpression; if (objectCreateExpression == null) { return(null); } var initializerRR = context.Resolve(initializer) as LocalResolveResult; if (initializerRR == null) { return(null); } IList <AstNode> statements = GetNodes(context.GetNode <Statement>()); var converter = new StatementsToInitializerConverter(context); var newInitializer = converter.ConvertToInitializer(initializer, ref statements); if (newInitializer == null || statements.Count == 0) { return(null); } return(MakeAction(context, initializer, newInitializer, statements)); }