CodeImport.IsCodeType 屬性
取得值,指出是否可以從 CodeImport 物件取得 CodeType 物件。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
ReadOnly Property IsCodeType As Boolean
bool IsCodeType { get; }
property bool IsCodeType {
bool get ();
}
abstract IsCodeType : bool
function get IsCodeType () : boolean
屬性值
型別:System.Boolean
布林值,如果可以從 CodeImport 物件取得 CodeType 物件,則為 true,否則為 false。
備註
如果是 true,則可以查詢介面或將它轉型為 CodeType 物件。當 Kind 是 vsCMElementClass、vsCMElementInterface、vsCMElementDelegate、vsCMElementStruct 或 vsCMElementEnum 時,則為 true。
注意事項 |
---|
在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。 |
範例
Sub IsCodeTypeExample(ByVal dte As DTE2)
' NOTE: This example requires a reference to the System.Text
' namespace.
' Before running this example, open a code document from a project.
Dim item As ProjectItem = dte.ActiveDocument.ProjectItem
Dim sb As New StringBuilder
RecurseElements(item.FileCodeModel.CodeElements, 0, sb)
MsgBox(item.Name & " contains the following elements:" & vbCrLf & _
vbCrLf & sb.ToString())
End Sub
Sub RecurseElements(ByVal elems As CodeElements, _
ByVal level As Integer, ByVal sb As StringBuilder)
Dim elem As CodeElement
For Each elem In elems
' Add element to the list of names.
sb.Append(" "c, level * 8)
sb.Append(elem.Name & " [" & elem.Kind.ToString() & "]" & _
vbCrLf)
' Call this function recursively if element has children.
If elem.Kind = vsCMElement.vsCMElementNamespace Then
RecurseElements(CType(elem, CodeNamespace).Members, _
level + 1, sb)
ElseIf elem.IsCodeType Then
RecurseElements(CType(elem, CodeType).Members, _
level + 1, sb)
End If
Next
End Sub
public void IsCodeTypeExample(DTE2 dte)
{
// NOTE: This example requires a reference to the System.Text
// namespace.
// Before running this example, open a code document from a
// project.
ProjectItem item = dte.ActiveDocument.ProjectItem;
StringBuilder sb = new StringBuilder();
RecurseElements(item.FileCodeModel.CodeElements, 0, sb);
MessageBox.Show(item.Name + " contains the following elements:" +
Environment.NewLine + Environment.NewLine + sb.ToString());
}
void RecurseElements(CodeElements elems, int level, StringBuilder sb)
{
foreach (CodeElement elem in elems)
{
// Add element to the list of names.
sb.Append(' ', level * 8);
sb.Append(elem.Name + " [" + elem.Kind.ToString() + "]" +
Environment.NewLine);
// Call this function recursively if element has children.
if (elem.Kind == vsCMElement.vsCMElementNamespace)
RecurseElements(((CodeNamespace)elem).Members,
level + 1, sb);
else if (elem.IsCodeType)
RecurseElements(((CodeType)elem).Members, level + 1, sb);
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。