_DTE.GetObject(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取后期绑定到 DTE 对象的接口或对象,并且在运行时可通过名称访问。
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
参数
- Name
- String
必需。 要检索的对象的名称。
返回
后期绑定到 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);
}
注解
GetObject 对于不支持早期绑定的语言,最有用。 在这种情况下,可以为所需的特定接口或对象命名,例如 DTE.GetObject("VCProjects").
IExtenderSite.GetObject 仅支持将值 "DTE" 作为 Name 参数。 这是为了使扩展程序提供程序能够访问 DTE 对象。