CodeAttributeArgument.ProjectItem 属性

获取关联的 ProjectItem 对象。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
ReadOnly Property ProjectItem As ProjectItem
ProjectItem ProjectItem { get; }
property ProjectItem^ ProjectItem {
    ProjectItem^ get ();
}
abstract ProjectItem : ProjectItem with get
function get ProjectItem () : ProjectItem

属性值

类型:ProjectItem
一个 ProjectItem 对象

备注

备注

在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。

示例

' Macro code.
Sub codeArgNameExample()
    Dim sel As TextSelection = _
    CType(DTE.ActiveDocument.Selection, TextSelection)
    Dim cls As CodeClass2 = CType(sel.ActivePoint. _
    CodeElement(vsCMElement.vsCMElementClass), CodeClass2)
    Dim attr As CodeAttribute2
    Dim attrArg As CodeAttributeArgument
    Dim msg As String

    Try
        ' Loop through all of the attributes in the class.
        For Each attr In cls.Attributes
           ' Loop through all of the arguments for the attribute.
            For Each attrArg In attr.Arguments
                msg += "Value: " & attrArg.Value & " " & vbCr
                ' If the argument has a name, list it.
                If attrArg.Name <> Nothing Then
                    msg += "Name: " & attrArg.Name & vbCr
                End If
                msg += "Arg start pos: " & _
                attrArg.StartPoint.LineCharOffset & vbCr
                msg += "Arg end pos: " & _
                attrArg.EndPoint.LineCharOffset & vbCr
            Next
        Next
        msg += "Location: " & attrArg.InfoLocation.ToString & vbCr
        msg += "Is code type? " & attrArg.IsCodeType.ToString & vbCr
        msg += "Code element type: " & attrArg.Kind.ToString & vbCr
        msg += "Language: " & attrArg.Language & vbCr
        msg += ("Name of attribute's project item: " & _
        attrArg.ProjectItem.Name)
        ' List the arguments for the attribute.
        MsgBox("Attribute parameters for " & attr.Name _
        & ": " & vbCr & msg)
    Catch ex As System.Exception
        MsgBox("ERROR -> " & ex.Message)
    End Try
End Sub

.NET Framework 安全性

请参阅

参考

CodeAttributeArgument 接口

EnvDTE80 命名空间

其他资源

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

使用代码模型查找代码 (Visual Basic)

使用代码模型查找代码 (Visual C#)