/// <summary>Returns a collection of namespaces imported in the CSHTML file itself</summary> /// <param name="namespaces">A collection to add namespaces imported in the CSHTML file to</param> private void GetNamespacesFromFile(Collection <NamespaceImport> namespaces) { TextDocument doc = (TextDocument)this.Parent.Document.Object("TextDocument"); string contents = ExtensibilityMethods.GetDocumentText(doc); System.Text.RegularExpressions.Regex regExp = new Regex("@Imports[ \\t]+((.)*)", RegexOptions.IgnoreCase); Match m = regExp.Match(contents); if (m.Groups.Count > 0) { if (m.Groups[1].Value.Contains("=")) { var parts = m.Groups[1].Value.Split(new[] { '=' }, 2); namespaces.Add(new NamespaceImport(m.Groups[1].Value, parts[0].Trim(), parts[1].Trim())); } else { string ns = m.Groups[1].Value.Trim(); namespaces.Add(new NamespaceImport(ns, ns)); } } }
/// <summary>Returns the position of all comments in the given document using regular expressions</summary> /// <param name="item">Project item representing the document</param> /// <returns><see cref="Match"/> objects representing positions of all comments in the given documen</returns> public MatchCollection FindCommentsInDocument(ProjectItem item) { return(this.CommentRegularExpression.Matches(ExtensibilityMethods.GetDocumentText(GetDocumentForItem(item)).Replace("\r\n", "\n"))); }
/// <summary>Checks if selection in <see cref="TextDocument"/> is inside a hard coded string and return a <see cref="MatchResult"/> pointing to string.</summary> /// <param name="document">A <see cref="TextDocument"/> to look in part of</param> /// <param name="line">Current line</param> /// <param name="selectionStart">Starting index of the selection</param> /// <param name="selectionEnd">Ending index of the selection</param> /// <returns>A <see cref="MatchResult"/> object, result is false if a string could not be located.</returns> public MatchResult CheckForHardCodedString(TextDocument document, int selectionStart, int selectionEnd) { return(CheckForHardCodedString(ExtensibilityMethods.GetDocumentText(document).Replace("\r\n", "\n"), selectionStart, selectionEnd)); }