Solution2.Item 方法 (Object)
傳回 Projects 集合的索引成員。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
Function Item ( _
index As Object _
) As Project
Project Item(
Object index
)
Project^ Item(
[InAttribute] Object^ index
)
abstract Item :
index:Object -> Project
function Item(
index : Object
) : Project
參數
- index
型別:System.Object
必要項。所要傳回項目的索引。
傳回值
型別:EnvDTE.Project
Project 物件。
備註
傳遞給 Index 的值是整數,也就是物件在集合中的索引。 Index 值也可以是等於集合中物件的字串值。 但是,Item 接受的實際值,會視集合及其實作而有所不同。
如果集合無法找到對應於索引值的物件,Item 方法就會擲回 ArgumentException 例外狀況。
範例
如需如何執行增益集程式碼的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
下列範例會逐一查看開啟方案中的專案。
Public Sub OnConnection(ByVal application As Object, _
ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
SolnItemExample(_applicationObject)
End Sub
Sub SolnItemExample(ByVal dte As DTE2)
' This add-in iterates through project items in a solution.
' Make sure you have a solution open in Visual
' Studio before running this example.
Try
Dim soln As Solution2 = _
CType(_applicationObject.Solution, Solution2)
' Dim solnName As String = _
System.IO.Path.GetFileNameWithoutExtension(soln.FullName)
Dim tempString As String = "The items in the solution are: " _
& vbCr
For i As Integer = 1 To soln.Projects.Count
tempString = tempString & soln.Item(i).Name.ToString() _
& vbCr
Next
MsgBox(tempString)
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End Sub
//make sure to add this reference to your project references
using System.Windows.Forms;
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst,
ref System.Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
SolnItemExample((DTE2)_applicationObject);
}
public void SolnItemExample(DTE2 dte)
{
// This add-in iterates through the project items in a solution.
// Open a solution in Visual Studio before running
// this example.
try
{
Solution2 soln = (Solution2)_applicationObject.Solution;
String tempString = "The items in the solution are: " + "\n";
for (int i = 1; i <= soln.Projects.Count; i++)
{
tempString = tempString + soln.Item(i).Name.ToString()
+ "\n";
}
MessageBox.Show(tempString);
}
catch (SystemException ex)
{
MessageBox.Show("ERROR: " + ex);
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。