Events2.GetObject Method
Returns an interface or object that is late-bound to the DTE object and can be accessed by name at run time.
Namespace: EnvDTE80
Assembly: EnvDTE80 (in EnvDTE80.dll)
Syntax
'Declaration
Function GetObject ( _
Name As String _
) As Object
Object GetObject(
string Name
)
Object^ GetObject(
[InAttribute] String^ Name
)
abstract GetObject :
Name:string -> Object
function GetObject(
Name : String
) : Object
Parameters
Name
Type: System.StringRequired. The name of the object to retrieve.
Return Value
Type: System.Object
An object.
Remarks
GetObject is most useful in languages that do not support early binding. In this case, you can name the specific interface or object you want, for example, DTE.GetObject("VCProjects").
IExtenderSite.GetObject only supports the value, DTE, as the Name parameter. This is provided for Extender Providers to get to the DTE object.
Examples
Sub GetObjectExample(ByVal dte As DTE2)
' NOTE: This example requires a reference to the
' Microsoft.VisualStudio.VCCodeModel namespace.
Dim idents() As String = {"short", "class", "void", "var"}
Dim langMan As VCLanguageManager = _
CType(dte.GetObject("VCLanguageManager"), VCLanguageManager)
' Validate the names in idents.
Dim name, msg As String
For Each name In idents
If langMan.ValidateIdentifier(name) Then
msg &= """" & name & """ is a valid identifier." & vbCrLf
Else
msg &= """" & name & """ is not a valid identifier." & _
vbCrLf
End If
Next
MsgBox(msg)
End Sub
public void GetObjectExample(DTE2 dte)
{
// NOTE: This example requires a reference to the
// Microsoft.VisualStudio.VCCodeModel namespace.
string[] idents = {"short", "class", "void", "var"};
VCLanguageManager langMan =
(VCLanguageManager)dte.GetObject("VCLanguageManager");
// Validate the names in idents.
string msg = "";
foreach (string name in idents)
{
if (langMan.ValidateIdentifier(name))
msg += "\"" + name + "\" is a valid identifier." +
Environment.NewLine;
else
msg += "\"" + name + "\" is not a valid identifier." +
Environment.NewLine;
}
MessageBox.Show(msg);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Other Resources
How to: Compile and Run the Automation Object Model Code Examples