当前位置: 首页>>代码示例>>C#>>正文


C# RefactoringContext.GetOffset方法代码示例

本文整理汇总了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);
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:27,代码来源:InsertAnonymousMethodSignatureAction.cs

示例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);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:25,代码来源:SplitStringAction.cs

示例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 ("@") ? "\" + @\"" : "\" + \"");
			}
		}	
开发者ID:KAW0,项目名称:Alter-Native,代码行数:8,代码来源:SplitString.cs

示例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 ());
			}
		}
开发者ID:hduregger,项目名称:monodevelop,代码行数:24,代码来源:InsertAnonymousMethodSignature.cs

示例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));
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:8,代码来源:IntroduceFormatItemAction.cs


注:本文中的RefactoringContext.GetOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。