static PrimitiveExpression CreateFormatString(RefactoringContext context, PrimitiveExpression pExpr, int argumentNumber) { var start = context.GetOffset(pExpr.StartLocation); var end = context.GetOffset(pExpr.EndLocation); return(new PrimitiveExpression("", context.GetText(start, context.SelectionStart - start) + "{" + argumentNumber + "}" + context.GetText(context.SelectionEnd, end - context.SelectionEnd))); }
public void Run(RefactoringContext context) { IType type; var anonymousMethodExpression = GetAnonymousMethodExpression(context, out type); var delegateMethod = type.GetDelegateInvokeMethod(); var sb = new StringBuilder("("); for (int k = 0; k < delegateMethod.Parameters.Count; k++) { if (k > 0) { sb.Append(", "); } var paramType = delegateMethod.Parameters [k].Type; sb.Append(context.CreateShortType(paramType)); sb.Append(" "); sb.Append(delegateMethod.Parameters [k].Name); } sb.Append(")"); using (var script = context.StartScript()) { script.InsertText(context.GetOffset(anonymousMethodExpression.DelegateToken.EndLocation), sb.ToString()); } }
public override IEnumerable <CodeAction> GetActions(RefactoringContext context) { IType type; var anonymousMethodExpression = GetAnonymousMethodExpression(context, out type); if (anonymousMethodExpression == null) { yield break; } yield return(new CodeAction(context.TranslateString("Insert anonymous method signature"), script => { var delegateMethod = type.GetDelegateInvokeMethod(); var sb = new StringBuilder("("); for (int k = 0; k < delegateMethod.Parameters.Count; k++) { if (k > 0) { sb.Append(", "); } var paramType = delegateMethod.Parameters [k].Type; sb.Append(context.CreateShortType(paramType)); sb.Append(" "); sb.Append(delegateMethod.Parameters [k].Name); } sb.Append(")"); script.InsertText(context.GetOffset(anonymousMethodExpression.DelegateToken.EndLocation), sb.ToString()); }, anonymousMethodExpression)); }
public override IEnumerable<CodeAction> GetActions(RefactoringContext context) { if (context.IsSomethingSelected) { yield break; } var pexpr = context.GetNode<PrimitiveExpression>(); if (pexpr == null || !(pexpr.Value is string)) { yield break; } if (pexpr.LiteralValue.StartsWith("@", StringComparison.Ordinal)) { if (!(pexpr.StartLocation < new TextLocation(context.Location.Line, context.Location.Column - 2) && new TextLocation(context.Location.Line, context.Location.Column + 2) < pexpr.EndLocation)) { yield break; } } else { if (!(pexpr.StartLocation < new TextLocation(context.Location.Line, context.Location.Column - 1) && new TextLocation(context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation)) { yield break; } } yield return new CodeAction(context.TranslateString("Split string literal"), script => { int offset = context.GetOffset (context.Location); script.InsertText (offset, pexpr.LiteralValue.StartsWith("@", StringComparison.Ordinal) ? "\" + @\"" : "\" + \""); }, pexpr); }
public void Run(RefactoringContext context) { var pexpr = context.GetNode <PrimitiveExpression> (); int offset = context.GetOffset(context.Location); using (var script = context.StartScript()) { script.InsertText(offset, pexpr.LiteralValue.StartsWith("@") ? "\" + @\"" : "\" + \""); } }