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


C# IDocument.PositionToOffset方法代码示例

本文整理汇总了C#中IDocument.PositionToOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.PositionToOffset方法的具体用法?C# IDocument.PositionToOffset怎么用?C# IDocument.PositionToOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocument的用法示例。


在下文中一共展示了IDocument.PositionToOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveFieldDeclaration

		protected override void RemoveFieldDeclaration(IDocument document, IField field)
		{
			// In VB, the field region begins at the start of the declaration
			// and ends on the first column of the line following the declaration.
			int startOffset = document.PositionToOffset(field.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(field.Region.EndLine, 1);
			document.Remove(startOffset, endOffset - startOffset);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:8,代码来源:VBNetDesignerGenerator.cs

示例2: ReplaceFieldDeclaration

		protected override void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
		{
			// In VB, the field region begins at the start of the declaration
			// and ends on the first column of the line following the declaration.
			int startOffset = document.PositionToOffset(oldField.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(oldField.Region.EndLine, 1);
			document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:8,代码来源:VBNetDesignerGenerator.cs

示例3: BuildConverter

 /// <summary>
 /// Builds converter from <c>DomRegion</c> and <c>IDocument</c>.
 /// </summary>
 /// <param name="region">DomRegion</param>
 /// <param name="doc">Document</param>
 /// <returns>Convertor</returns>
 public static LineOffsetConverter BuildConverter(DomRegion region, IDocument doc)
 {
     LineOffsetConverter lineCon = new LineOffsetConverter();
     lineCon.startLine = region.BeginLine;
     int stOffset = doc.PositionToOffset(region.BeginLine,0);
     for(int i = region.BeginLine;i <= region.EndLine; i++){
         lineCon.lineOffsets.Add(doc.PositionToOffset(i,0) - stOffset);
     }
     return lineCon;
 }
开发者ID:maresja1,项目名称:SDenc,代码行数:16,代码来源:LineOffsetConverter.cs

示例4: AddMarker

		public void AddMarker(IDocument document, CodeCoverageSequencePoint sequencePoint)
		{
			if (!IsValidSequencePoint(document, sequencePoint)) {
				return;
			}
			
			ITextMarkerService markerService = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			if (markerService != null) {
				int startOffset = document.PositionToOffset(sequencePoint.Line, sequencePoint.Column);
				int endOffset = document.PositionToOffset(sequencePoint.EndLine, sequencePoint.EndColumn);
				ITextMarker marker = markerService.Create(startOffset, endOffset - startOffset);
				marker.Tag = typeof(CodeCoverageHighlighter);
				marker.BackgroundColor = GetSequencePointColor(sequencePoint);
				marker.ForegroundColor = GetSequencePointForeColor(sequencePoint);
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:16,代码来源:CodeCoverageHighlighter.cs

示例5: Resolve

 /// <summary>
 /// Attempts to resolve a reference to a resource.
 /// </summary>
 /// <param name="fileName">The name of the file that contains the expression to be resolved.</param>
 /// <param name="document">The document that contains the expression to be resolved.</param>
 /// <param name="caretLine">The 0-based line in the file that contains the expression to be resolved.</param>
 /// <param name="caretColumn">The 0-based column position of the expression to be resolved.</param>
 /// <param name="charTyped">The character that has been typed at the caret position but is not yet in the buffer (this is used when invoked from code completion), or <c>null</c>.</param>
 /// <returns>A <see cref="ResourceResolveResult"/> that describes which resource is referenced by the expression at the specified position in the specified file, or <c>null</c> if that expression does not reference a (known) resource or if the specified position is invalid.</returns>
 public ResourceResolveResult Resolve(string fileName, IDocument document, int caretLine, int caretColumn, char? charTyped)
 {
     if (fileName == null || document == null) {
         LoggingService.Debug("ResourceToolkit: "+this.GetType().ToString()+".Resolve called with null fileName or document argument");
         return null;
     }
     if (caretLine < 0 || caretColumn < 0 || caretLine >= document.TotalNumberOfLines || caretColumn >= document.GetLine(caretLine + 1).TotalLength) {
         LoggingService.Debug("ResourceToolkit: "+this.GetType().ToString()+".Resolve called with invalid position arguments");
         return null;
     }
     return this.Resolve(fileName, document, caretLine, caretColumn, document.PositionToOffset(caretLine + 1, caretColumn + 1), charTyped);
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:21,代码来源:AbstractResourceResolver.cs

示例6: AttachTo

		internal void AttachTo(IDocument document)
		{
			if (isDeleted)
				return;
			Debug.Assert(currentDocument == null && document != null);
			this.currentDocument = document;
			line = Math.Min(line, document.TotalNumberOfLines);
			column = Math.Min(column, document.GetLine(line).Length + 1);
			baseAnchor = document.CreateAnchor(document.PositionToOffset(line, column));
			baseAnchor.MovementType = movementType;
			baseAnchor.SurviveDeletion = surviveDeletion;
			baseAnchor.Deleted += baseAnchor_Deleted;
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:13,代码来源:PermanentAnchor.cs

示例7: GetInnermostElement

		XElement GetInnermostElement(XElement parent, IDocument document, int offset)
		{
			int startOffset = document.PositionToOffset(parent.GetLineNumber(), parent.GetLinePosition());
			int endOffset = parent.ToString().Length + startOffset;
			
			if (startOffset > offset || endOffset < offset)
				return null;
			
			foreach (XElement element in parent.Elements()) {
				XElement innermostElement = GetInnermostElement(element, document, offset);
				if (innermostElement != null)
					return innermostElement;
			}
			
			return parent;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:16,代码来源:ExtractPropertiesAsStyleCommand.cs

示例8: GetCursorLine

		protected override int GetCursorLine(IDocument document, IMethod method)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			if (method == null)
				throw new ArgumentNullException("method");
			
			DomRegion r = method.BodyRegion;
			int offset = document.PositionToOffset(new TextLocation(r.BeginColumn - 1, r.BeginLine - 1));
			while (offset < document.TextLength) {
				char c = document.GetCharAt(offset++);
				if (c == '{') {
					return r.BeginLine + 1;
				}
				if (c != ' ') {
					break;
				}
			}
			return r.BeginLine + 2;
		}
开发者ID:kingjiang,项目名称:SharpDevelopLite,代码行数:20,代码来源:CSharpDesignerGenerator.cs

示例9: ReplaceFieldDeclaration

		/// <summary>
		/// Replaces a field declaration in the source code document.
		/// </summary>
		/// <remarks>
		/// The default implementation assumes that the field region starts at the very beginning
		/// of the line of the field declaration and ends at the end of that line.
		/// Override this method if that is not the case in a specific language.
		/// </remarks>
		protected virtual void ReplaceFieldDeclaration(IDocument document, IField oldField, string newFieldDeclaration)
		{
			int startOffset = document.PositionToOffset(oldField.Region.BeginLine, 1);
			int endOffset   = document.PositionToOffset(oldField.Region.EndLine + 1, 1);
			document.Replace(startOffset, endOffset - startOffset, tabs + newFieldDeclaration + Environment.NewLine);
		}
开发者ID:TiberiuGal,项目名称:SharpDevelop,代码行数:14,代码来源:AbstractDesignerGenerator.cs

示例10: GetStartOffset

		/// <summary>
		/// Gets the start offset of the region.
		/// </summary>
		static int GetStartOffset(IDocument document, DomRegion region)
		{
			return document.PositionToOffset(region.BeginLine, region.BeginColumn);			
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:7,代码来源:ScriptingDesignerGenerator.cs

示例11: SwapText

		/// <summary>
		/// Swaps 2 ranges of text in a document.
		/// </summary>
		static void SwapText(IDocument document, Location start1, Location end1, Location start2, Location end2)
		{
			if (start1 > start2) {
				Location sw;
				sw = start1; start1 = start2; start2 = sw;
				sw = end1; end1 = end2; end2 = sw;
			}
			if (end1 >= start2)
				throw new InvalidOperationException("Cannot swap overlaping segments");
			int offset1 = document.PositionToOffset(start1);
			int len1 = document.PositionToOffset(end1) - offset1;
			int offset2 = document.PositionToOffset(start2);
			int len2 = document.PositionToOffset(end2) - offset2;
			
			string text1 = document.GetText(offset1, len1);
			string text2 = document.GetText(offset2, len2);
			
			using (var undoGroup = document.OpenUndoGroup()) {
				document.Replace(offset2, len2, text1);
				document.Replace(offset1, len1, text2);
			}
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:25,代码来源:CodeManipulation.cs

示例12: IsWhitespaceBetween

		static bool IsWhitespaceBetween(IDocument document, Location startPos, Location endPos)
		{
			int startOffset = document.PositionToOffset(startPos);
			int endOffset = document.PositionToOffset(endPos);
			return string.IsNullOrWhiteSpace(document.GetText(startOffset, endOffset - startOffset));
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:6,代码来源:CodeManipulation.cs

示例13: FindBeginStatement

		static int FindBeginStatement(IDocument document, VBStatement statement, Location endLocation, out int length)
		{
			ILexer lexer = ParserFactory.CreateLexer(SupportedLanguage.VBNet, document.CreateReader());
			
			Token currentToken = null;
			Token prevToken = null;
			
			int lookFor = statement.StatementToken;
			Stack<Token> tokens = new Stack<Token>();
			
			if (statement.EndStatement == "Next") {
				lookFor = Tokens.For;
			}
			
			Token result = null;
//			Token firstModifier = null;
			
			while ((currentToken = lexer.NextToken()).Kind != Tokens.EOF) {
				if (prevToken == null)
					prevToken = currentToken;
				
//				if (IsModifier(currentToken)) {
//					if (firstModifier == null)
//						firstModifier = currentToken;
//				} else
//					firstModifier = null;
				
				
				if (VBNetFormattingStrategy.IsBlockStart(lexer, currentToken, prevToken)) {
					tokens.Push(currentToken);
				}
				if (VBNetFormattingStrategy.IsBlockEnd(currentToken, prevToken)) {
					while (tokens.Count > 0 && !VBNetFormattingStrategy.IsMatchingEnd(tokens.Peek(), currentToken))
						tokens.Pop();
					if (tokens.Count > 0) {
						Token t = tokens.Pop();
						if (currentToken.Location.Line == endLocation.Line) {
							result = t;
							break;
						}
					}
				}
				
				prevToken = currentToken;
			}
			
			if (result != null) {
				int endOffset = document.PositionToOffset(result.EndLocation.Line, result.EndLocation.Column);
				int offset = document.PositionToOffset(result.Location.Line, result.Location.Column);
				length = endOffset - offset;
				return offset;
			}
			
			length = 0;
			
			return -1;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:57,代码来源:VBNetBracketSearcher.cs

示例14: ExtendLeft

		/// <summary>
		/// If the text at startPos is preceded by any of the prefixes, moves the start backwards to include one prefix
		/// (the rightmost one).
		/// </summary>
		Location ExtendLeft(Location startPos, IDocument document, params String[] prefixes)
		{
			int startOffset = document.PositionToOffset(startPos);
			foreach (string prefix in prefixes) {
				if (startOffset < prefix.Length) continue;
				string realPrefix = document.GetText(startOffset - prefix.Length, prefix.Length);
				if (realPrefix == prefix) {
					return document.OffsetToPosition(startOffset - prefix.Length);
				}
			}
			// no prefixes -> do not extend
			return startPos;
		}
开发者ID:GMRyujin,项目名称:SharpDevelop,代码行数:17,代码来源:CodeManipulation.cs

示例15: IsWhitespaceBetween

		bool IsWhitespaceBetween(IDocument document, Location startPos, Location endPos)
		{
			int startOffset = document.PositionToOffset(startPos);
			int endOffset = document.PositionToOffset(endPos);
			if (startOffset > endOffset) {
				throw new ArgumentException("Invalid range for (startPos, endPos)");
			}
			return string.IsNullOrWhiteSpace(document.GetText(startOffset, endOffset - startOffset));
		}
开发者ID:GMRyujin,项目名称:SharpDevelop,代码行数:9,代码来源:CodeManipulation.cs


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