本文整理汇总了C#中RefactoringContext.GetOffset方法的典型用法代码示例。如果您正苦于以下问题:C# RefactoringContext.GetOffset方法的具体用法?C# RefactoringContext.GetOffset怎么用?C# RefactoringContext.GetOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RefactoringContext
的用法示例。
在下文中一共展示了RefactoringContext.GetOffset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActions
public 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);
}
示例2: GetActions
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);
}
示例3: Run
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 ("@") ? "\" + @\"" : "\" + \"");
}
}
示例4: Run
public void Run (RefactoringContext context)
{
ITypeDefinition type;
var anonymousMethodExpression = GetAnonymousMethodExpression (context, out type);
var delegateMethod = type.Methods.First ();
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 (paramType.ToString ());
sb.Append (" ");
sb.Append (delegateMethod.Parameters [k].Name);
}
sb.Append (")");
using (var script = context.StartScript ()) {
script.InsertText (context.GetOffset (anonymousMethodExpression.DelegateToken.EndLocation), sb.ToString ());
}
}
示例5: CreateFormatString
static PrimitiveExpression CreateFormatString(RefactoringContext context, PrimitiveExpression pExpr, int argumentNumber)
{
var start = context.GetOffset(pExpr.StartLocation);
var end = context.GetOffset(pExpr.EndLocation);
var sStart = context.GetOffset(context.SelectionStart);
var sEnd = context.GetOffset(context.SelectionEnd);
return new PrimitiveExpression("", context.GetText(start, sStart - start) + "{" + argumentNumber + "}" + context.GetText(sEnd, end - sEnd));
}