Freigeben über


DTE2.GetObject(String) Method

Definition

Gets an interface or object that is late-bound to the DTE object and can be accessed by name at run time.

public:
 System::Object ^ GetObject(System::String ^ Name);
public:
 Platform::Object ^ GetObject(Platform::String ^ Name);
winrt::Windows::Foundation::IInspectable GetObject(std::wstring const & Name);
[System.Runtime.InteropServices.DispId(211)]
public object GetObject (string Name);
[<System.Runtime.InteropServices.DispId(211)>]
abstract member GetObject : string -> obj
Public Function GetObject (Name As String) As Object

Parameters

Name
String

Required. The name of the object to retrieve.

Returns

An interface or object that is late-bound to the DTE object.

Implements

Attributes

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);  
}  

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.

Applies to