public override IEnumerable <CodeAction> GetActions(RefactoringContext context) { // lambda var lambda = context.GetNode <LambdaExpression> (); if (lambda != null && lambda.ArrowToken.Contains(context.Location)) { if (ContainsLocalReferences(context, lambda, lambda.Body)) { yield break; } bool noReturn = false; BlockStatement body; if (lambda.Body is BlockStatement) { body = (BlockStatement)lambda.Body.Clone(); } else { if (!(lambda.Body is Expression)) { yield break; } body = new BlockStatement(); var type = LambdaHelper.GetLambdaReturnType(context, lambda); if (type == null || type.ReflectionName == "System.Void") { noReturn = true; body.Add((Expression)lambda.Body.Clone()); } else { body.Add(new ReturnStatement((Expression)lambda.Body.Clone())); } } var method = GetMethod(context, (LambdaResolveResult)context.Resolve(lambda), body, noReturn); yield return(GetAction(context, lambda, method)); } // anonymous method var anonymousMethod = context.GetNode <AnonymousMethodExpression> (); if (anonymousMethod != null && anonymousMethod.DelegateToken.Contains(context.Location)) { if (ContainsLocalReferences(context, anonymousMethod, anonymousMethod.Body)) { yield break; } var method = GetMethod(context, (LambdaResolveResult)context.Resolve(anonymousMethod), (BlockStatement)anonymousMethod.Body.Clone()); yield return(GetAction(context, anonymousMethod, method)); } }
static bool RequireReturnStatement(RefactoringContext context, LambdaExpression lambda) { var type = LambdaHelper.GetLambdaReturnType(context, lambda); return(type != null && type.ReflectionName != "System.Void"); }