获取后期绑定到 DTE 对象的接口或对象,并且在运行时可通过名称访问。
命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
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
参数
- Name
 类型:System.String
 必选。要检索的对象名。
返回值
类型:System.Object
后期绑定到 DTE 对象的接口或对象。
实现
备注
GetObject 在不支持早期绑定的语言中最有用。 这种情况下,可以给需要的特定接口或对象命名,如 DTE.GetObject("VCProjects")。
IExtenderSite.GetObject 只支持值 DTE 作为 Name 参数。 这是为扩展程序提供程序获取 DTE 对象而提供的。
示例
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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。