private void CopyFullyQualifiedNameInternal() { try { TextSelection sel = (TextSelection)dte.ActiveDocument.Selection; TextPoint pnt = sel.ActivePoint as TextPoint; if (pnt == null) { // Not in editor? Exit. ActivityLog.LogWarning(NameForLogging.Value, "Can't obtain TextPoint, returning."); } // Discover every code element containing the insertion point. FileCodeModel fcm = dte.ActiveDocument.ProjectItem.FileCodeModel; vsCMElement scopes = 0; // Super-dumb way of getting fully qualified name - find longest full name // Seems to be working. It is late and I don't want to invent some heuristic that depend on the Scope type string longestName = string.Empty; foreach (vsCMElement scope in Enum.GetValues(scopes.GetType())) { CodeElement elem = null; try { elem = fcm.CodeElementFromPoint(pnt, scope); if (elem != null) { var name = elem.FullName; if (name.Length > longestName.Length) { longestName = name; } } } catch (Exception ex) { ActivityLog.LogInformation(this.GetType().FullName, "Unable to get code element, exception: " + ex.Message); continue; } } if (!string.IsNullOrWhiteSpace(longestName)) { Clipboard.SetText(longestName); } } catch (Exception ex) { ActivityLog.LogError(this.GetType().FullName, "Error when trying to copy fully qualified name: " + ex.Message); } }
private void dumpCursorInfo(TextPoint cursor) { // Discover every code element containing the insertion point. string elems = ""; vsCMElement scopes = 0; foreach (vsCMElement scope in Enum.GetValues(scopes.GetType())) { CodeElement elem = cursor.CodeElement[scope]; if (elem != null) { elems += elem.Name + " (" + scope.ToString() + ")\n"; } } Debug.WriteLine(elems); }
private OnDemandRun getFromCodeModel() { try { getCodeFromPosition(); foreach (vsCMElement scope in Enum.GetValues(_scopes.GetType())) { if (!validScope(scope)) { continue; } try { CodeElement elem = _fcm.CodeElementFromPoint(_point, scope); if (elem == null) { continue; } analyzeElement(elem); } catch (Exception ex) { AutoTest.Core.DebugLog.Debug.WriteException(ex); } } } catch (Exception ex) { AutoTest.Core.DebugLog.Debug.WriteException(ex); } if (_test.Length > 0 || _member.Length > 0) { return(new OnDemandRun(_project, _test, _member, new string[] { })); } else { return(new OnDemandRun(_project, _test, _member, _namespace)); } }
private void CodeModelCmdEvent_Click(object CommandBarControl, ref bool Handled, ref bool CancelDefault) { TextSelection selected = _applicationObject.ActiveDocument.Selection as TextSelection; //EditPoint topPoint = selected.TopPoint.CreateEditPoint(); //EditPoint bottomPoint = selected.BottomPoint.CreateEditPoint(); TextPoint pnt = (TextPoint)selected.ActivePoint; vsCMElement scopes = 0; string elems = string.Empty; foreach (vsCMElement scope in Enum.GetValues(scopes.GetType())) { CodeElement elem = pnt.get_CodeElement(scope); if (elem != null) { elems += elem.Name + " (" + scope.ToString() + ") \n"; } } MessageBox.Show(elems); }
private static void CodeElementsByScopes(StringBuilder sb, VirtualPoint activePoint) { sb.AppendLine("Code elements"); string elems = ""; vsCMElement scopes = 0; foreach (vsCMElement scope in Enum.GetValues(scopes.GetType())) { CodeElement elem = activePoint.get_CodeElement(scope); if (elem != null) { elems += elem.Name + " (" + scope.ToString() + ")\n"; } } sb.Append(elems); }