CHAPTER 17
This chapter contains a summary of some of the basic object classes you can use to interact with Visual Studio.
The application object (typically stored in the variable _applicationObject) is an encapsulation of everything within the Visual Studio IDE.
Property | Data Type | Description |
|---|---|---|
ActiveDocument | Document | Currently active document. |
ActiveSolutionProjects | Collection of projects | Collection of all projects in current solution. |
ActiveWindow | Window | Currently active or topmost window. |
Addins | Collection | Collection of all available add-ins. |
CommandBars | Command Bar | Access to Visual Studio commands and menus. |
CommandLineArgument | String | Command-line arguments passed to Visual Studio when it was started. |
Debugger | Debugger | Access to Visual Studio debugger object. |
DisplayMode | Enum | DisplayMDI or DisplayMDITabs. |
Documents | Collection | Collection of open documents in the IDE. |
Edition | String | Ultimate, Premium, Professional, or Express. |
FullName | String | Full path and file name. |
ItemOperations | Object | Allows file manipulation within Visual Studio. |
LocaleID | Integer | Geographic region, 1033-United States, etc. |
MainWindow | Window | Main window of the development environment. |
Mode | Enum | IDE Mode Design or IDE Mode Debug. |
RegistryRoot | String | Root key in registry where settings are stored. |
Solution | Solution | Current solution object. |
ToolWindows | Tool Window | Shortcut access object to IDE tool windows. |
Version | String | 10.0, 12.0, etc. |
Windows | Collection | Collection of all open IDE windows. |
Windows represent tool windows or editing forms used by Visual Studio. Tool windows include the Solution Explorer, Properties, the Tool Box, etc. Document windows are editing windows containing document objects that represent the source code being edited by the user. See Chapters 9 and 10 for examples and more details.
Property | Data Type | Description |
|---|---|---|
ActiveWindow | Window | Window the document is open in. |
FullName | String | Full path and file name of file in the document. |
Kind | String | GUID string indicating type of document. |
Name | String | Name of the document. |
Path | String | Full path, without the file name. |
ProjectItem | ProjectItem | Item within the project associated with the document. |
Saved | Boolean | True if the document has not been modified since last open. |
Selection | Selection | Current selection text in document. |
Methods | ||
Activate | Move focus to the document. | |
Close | Close, and optionally save the document. | |
NewWindow | Create a new window to view the document. | |
Object | Run-time object associated with the document. | |
Redo | Re-execute last action that was undone. | |
Save | Save the document to disk. | |
Undo | Reverse last action performed on document. | |
The window represents either a tool window or a document window that contains text being edited.
Property | Data Type | Description |
|---|---|---|
AutoHides | Boolean | Can the tool window be hidden? |
Caption | String | The window title. |
Document | Document | The document in the window (if one exists). |
Height | Integer | Height of the window in pixels. |
Kind | String | Either “Tool” or “Document”. |
Left | Integer | Distance from left edge of the container in pixels. |
Object | Object | Allow run-time access to contents in the window, most of Object(“TextDocument”). |
ObjectKind | String | A GUID representing the tool contained in the window. |
Project | Project | The project associated with the window. |
ProjectItem | ProjectItem | The project element associated with the window. |
Selection | Selection object | The currently selected text in the window. |
Top | Integer | Distance from the top edge of the container in pixels. |
Visible | Boolean | Is the window currently visible? |
Width | Integer | Width of window, in pixels. |
WindowState | Enum | vsWindowStateNormal, StateMinimize, or StateMaximize. |
Methods | ||
Activate | Move focus to the window. | |
Close | Close and optionally save the document. | |
SetTabPicture | Set a picture to display for a tool window. | |
The solution object represents a solution and its component projects, which you can manipulate easily. See Chapters 8 and 9 for more information.
The following table lists the solution properties of _applicationObject.
Property | Data Type | Description |
|---|---|---|
AddIns | Collection | Collection of add-in objects associated with the solution. |
FullName | String | Path and file name of the solution. |
Globals | Collection | Global variables saved with solution. |
IsOpen | Boolean | Is the solution open? |
Projects | Collection | Collection of all projects in the solution. |
Properties | Collection | Names and values of all solution properties. |
Saved | Boolean | Has the solution been saved? |
SolutionBuild | SolutionBuild | An object with build information of the solution. |
TemplatePath | String object | Template path for type of project, i.e. C#, VB. |
Methods | ||
AddFromFile | Add an existing file to the project. | |
AddFromTemplate | Copy a template file and add it to the solution. | |
Close | Close the solution. | |
Create | Create an empty solution. | |
FindProjectItem | Find an item in a project. | |
Item | Get a project in the solution. | |
Open | Open the solution. | |
ProjectItemsTemplatePath | Return location of project item templates for specific project types. | |
Remove | Remove specified project from solution. | |
SaveAs | Save solution under another name. | |
You can iterate through the solution's Projects collection to get details on any given project in the solution space.
Property | Data Type | Description | |
|---|---|---|---|
CodeModel | Object | Code Model (access to source elements). | |
FullName | String | Full path and file name of the project. | |
Globals | Collection | Global add-in values associated with the project. | |
Kind | GUID String | Type of solution, VB or C#, for example. | |
Name | String | Short project name. | |
ProjectItems | Collection | Collection of items making up the project. | |
Properties | Collection | Properties associated with the project. | |
Saved | Boolean | Has the project been saved? | |
UniqueName | String | Unique name for the project. | |
Methods | |||
Save | Save the project or project item. | ||
SaveAs | Save as a new file name. | ||
Project items are the files (source, XML files, etc.) that make up the project.
Property | Data Type | Description |
ContainingProject | Project | The project hosting the project item or file. |
Document | Object | A document object (if any exist) for the file. |
FileCodeModel | Code Model | Allows you to access high-level code elements within the source file. |
FileCount | Integer | Number of files associated with the project item. |
FileNames | Collection | File names associated with the item. |
IsOpen | Boolean | Is the project item open? |
Kind | GUID | Type of the item. |
Name | String | Name of the project item. |
Object | Object | Run-time object associated with the project item. |
Properties | Collection | Properties associated with the item. |
Saved | Boolean | Has project item been modified since last open? |
Methods | ||
Delete | Remove project from solution and storage. | |
ExpandView | Expand solution explorer view to show project. | |
Open | Open the project item. | |
Remove | Remove item from project and delete from disk. | |
Save | Save project item. | |
SaveAs | Save project item under another file name. | |
These objects are the basic tools to manipulate text in source windows, both using simple string manipulations and the more complex code model parser. See Chapters 12 and 13 for some example usage.
Property | Data Type | Description | |
|---|---|---|---|
EndPoint | Text point | A point referring to the end of the document. | |
Selection | Object | The currently selected text. | |
StartPoint | Text point | A point referring to the start of the document. | |
Methods | |||
ClearBookmarks | Remove all unnamed bookmarks from the text document. | ||
CreateEditPoint | Create a point object to edit text within the document. | ||
MarkText | Create unnamed bookmarks for all found text in document. | ||
ReplacePattern | Replace patterns within entire document or range. | ||
ReplaceText | Simple text replacement with document. | ||
Property | Data Type | Description |
|---|---|---|
AtEndOfDocument | Boolean | Is the point positioned at the document’s end? |
AtEndOfLine | Boolean | Is the object at the end of the line? |
AtStartOfDocument | Boolean | Is the point positioned at the start of the document? |
AtStartOfLine | Boolean | Is the object at the start of a line? |
CodeElement | Object | Return the code element at the current position. |
DisplayColumn | Integer | The current column containing the point. |
Line | Integer | The current line number in the document. |
LineLength | Integer | Number of characters in the current line. |
Methods | ||
ChangeCase | Change case of selected text. | |
CharLeft | Move edit point specified number of characters to the left. | |
CharRight | Move edit point specified number of characters to the right. | |
ClearBookmark | Clear any unnamed bookmark on the current line. | |
Copy | Copy range of text to clipboard. | |
Cut | Copy text to clipboard and delete from document. | |
Delete | Delete text from document. | |
GetLines | Get lines of text between two lines. | |
GetText | Get string of text. | |
Insert | Insert text into document. | |
LineDown | Move down one line. | |
LineUp | Move up one line. | |
MoveToLineAndOffset | Move to a line and character offset. | |
Paste | Paste contents of clipboard at current point. | |
ReplaceText | Replace selected text with given text. | |
WordLeft | Move specified number of words to the left. | |
WordRight | Move specified number of words to the right. | |
Using the code model is discussed in Chapter 13.
Property | Data Type | Description |
|---|---|---|
CodeElements | Collection | All the code element objects at this level. |
IsCaseSenstive | Boolean | Is the current language case sensitive? |
Language | String | Language the file is coded in. |
Methods | ||
AddClass | Create a code class construct. | |
AddEnum | Create an enum construct in the code. | |
AddFunction | Create new function code. | |
AddInterface | Create new interface code. | |
AddNamespace | Create a new namespace in the module. | |
AddVariable | Create new variable code. | |
IsValidID | Is the specified identifier valid in the current language? | |
Remove | Remove code element from file. | |
Property | Data Type | Description |
|---|---|---|
Children | Collection | Collection of child code elements. |
EndPoint | Text Point | Ending location for this element in file. |
FullName | String | Fully qualified code element name. |
InfoLocation | Enum | Is code element in project or external. |
IsCodeType | Boolean | Can a code type object be obtained from the element? |
Kind | Enum | Type of code element, i.e. class, function, etc. |
Language | String | Language the code element is written in. |
Name | String | Short name of the code element. |
ProjectItem | ProjectItem | The project item associated with the code element. |
StartPoint | Text Point | Starting location of the code element within the file. |