Mono.TextEditor.TextDocument.LocationToOffset C# (CSharp) Method

LocationToOffset() public method

public LocationToOffset ( DocumentLocation location ) : int
location DocumentLocation
return int
		public int LocationToOffset (DocumentLocation location)
		{
//			if (location.Column < DocumentLocation.MinColumn)
//				throw new ArgumentException ("column < MinColumn");
			if (location.Line > this.splitter.Count || location.Line < DocumentLocation.MinLine)
				return -1;
			DocumentLine line = GetLine (location.Line);
			return System.Math.Min (TextLength, line.Offset + System.Math.Max (0, System.Math.Min (line.Length, location.Column - 1)));
		}
		

Same methods

TextDocument::LocationToOffset ( int line, int column ) : int

Usage Example

		protected override void Run (object dataItem)
		{
			base.Run (dataItem);

			if (IdeApp.Workspace == null) return;
			if (IdeApp.Workbench.ActiveDocument == null || IdeApp.Workbench.ActiveDocument.FileName == FilePath.Null) return;

			var document = IdeApp.Workbench.ActiveDocument;

			ResolveResult resolveResult = null;
			object item = CurrentRefactoryOperationsHandler.GetItem (document, out resolveResult);

			IMethod method = item as IMethod;
			if (method == null)
				return;

			ISearchProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);
			ThreadPool.QueueUserWorkItem((data) => 
			{
				try
				{
					ImplementationsFinder.Find(method, implementation =>
					{
						FileProvider fileProvider = new FileProvider(implementation.Region.FileName);
						TextDocument doc = new TextDocument();
						doc.Text = fileProvider.ReadString();
						int offset = doc.LocationToOffset(implementation.Region.BeginLine, implementation.Region.BeginColumn);
						while ((offset + implementation.Name.Length) < doc.TextLength)
						{
							if (doc.GetTextAt(offset, implementation.Name.Length) == implementation.Name)
							{
								break;
							}
							offset++;
						}

						monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult(fileProvider, offset, implementation.Name.Length));
					});
				}
				catch (Exception exception)
				{
					if (monitor != null)
					{
						monitor.ReportError("Error finding references", exception);
					}
					else
					{
						LoggingService.LogError("Error finding references", exception);
					}
				}
				finally
				{
					if (monitor != null)
					{
						monitor.Dispose();
					}
				}
			});
		}
All Usage Examples Of Mono.TextEditor.TextDocument::LocationToOffset
TextDocument