Compartilhar via


CodeElement2.ElementID Property

Gets a value that uniquely identifies the element. Not implemented in Visual C#.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
ReadOnly Property ElementID As String
string ElementID { get; }
property String^ ElementID {
    String^ get ();
}
abstract ElementID : string with get
function get ElementID () : String

Property Value

Type: String
A string representing the unique value for the element.

Remarks

The ElementID property is a value that is calculated based on the element name and other information that uniquely identifies the element. The exact calculation of the ID varies between languages.

This ID is used by Code Model clients to keep track of elements without retaining references. It is included in Code Model events to inform the client code of the element that is changing. New IDs are provided when they are created.

The value of the ElementID property should not be considered permanent. It is likely to change each time the code model is created for a project and may also change in the current session. An ElementChanged event occurs each time the ElementID changes.

Note

You cannot call RenameSymbol or ElementID latebound. (For example, DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements.Item("Class1").RenameSymbol("Class2").) You must explicitly cast the object to the CodeElement2 interface before making the call.

Code elements in EnvDTE80 (hereafter called Code*2 objects) derive from those in EnvDTE. (For example, CodeClass2 derives from CodeClass, and CodeElement2 derives from CodeElement.) Internally in Visual Studio, all code elements (in both assemblies) are in turn cast to CodeElement2. So, logically, it is as if CodeClass2, for example, ultimately derives from CodeElement2.

Since the two elements are in reality in two separate inheritance hierarchies, though, the latebinder cannot look up CodeElement2 methods on Code*2 objects. EnvDTE works essentially the same way, but the use of pre-processor macros allows the interfaces to be defined such that inherited methods are explicitly defined on all of the related interfaces for which conversions exist. EnvDTE80 interfaces are defined using a similar inheritance scheme, only without the use of pre-processor statements. This is a more elegant solution since it eliminates redundant properties, but the result is that the properties cannot be called latebound. To work around this issue, explicitly cast the object to the CodeElement2 interface before making the call.

Also, the values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

.NET Framework Security

See Also

Reference

CodeElement2 Interface

EnvDTE80 Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples

Discovering Code by Using the Code Model (Visual Basic)

Discovering Code by Using the Code Model (Visual C#)