C# Source Code: Re: Iterating through the contents of the ROT (running objects table)
[
Home
|
Contents
|
Search
|
Reply
|
Previous
| Next ]
C# Source Code
Re: Iterating through the contents of the ROT (running objects table)
By:
Andres Rohr
Email (spam proof):
Email the originator of this post
Date:
Friday, May 11, 2012
Hits:
625
Category:
COM/Interop
Article:
Thanks a lot, works like a charm! Here are two utility methods that are used frequently based on this code: ///
/// Scans all open Visuals Studio sessions of any version for the one that has a special document opened. If not found /// 'null' is returned. ///
///
Absolute file path to a document that is open in this solution ///
The found DTE2 object or null
public static DTE2 FindSolutionWithOpenDocument(string documentPath) { Hashtable runningObjects = ROTHelper.GetActiveObjectList(null); foreach (DictionaryEntry de in runningObjects) { string progId = de.Key.ToString(); if (progId.Contains("VisualStudio.DTE.")) { DTE2 dte2 = (DTE2)ROTHelper.GetActiveObject(progId); // Find the document in the solution foreach (Document doc in dte2.Documents) { if (string.Equals(doc.FullName, documentPath, StringComparison.CurrentCultureIgnoreCase)) { return dte2; } } } } return null; } ///
/// Scans all open Visuals Studio sessions of any version for the one that is named 'name' (without ".sln"). If not found /// 'null' is returned. ///
///
Solution name without directory or extension ///
The found DTE2 object or null
public static DTE2 FindSolution(string pureName) { Hashtable runningObjects = ROTHelper.GetActiveObjectList(null); foreach (DictionaryEntry de in runningObjects) { string progId = de.Key.ToString(); if (progId.Contains("VisualStudio.DTE.")) { DTE2 dte2 = (DTE2)ROTHelper.GetActiveObject(progId); if (string.Equals(Path.GetFileNameWithoutExtension(dte2.Solution.FileName), pureName)) { return dte2; } } } return null; }
Terms and Conditions
Support this site
Download a trial version of the best FTP application on the internet