Share via


_DTE.GetObject 方法

获取后期绑定到 DTE 对象的接口或对象,并且在运行时可通过名称访问。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.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
    类型:String

    必需。 要检索的对象名。

返回值

类型: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 安全性

请参阅

参考

_DTE 接口

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例