CodeElement2.ElementID Property

Definition

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

public:
 property System::String ^ ElementID { System::String ^ get(); };
public:
 property Platform::String ^ ElementID { Platform::String ^ get(); };
[System.Runtime.InteropServices.DispId(200)]
public string ElementID { [System.Runtime.InteropServices.DispId(200)] get; }
[<System.Runtime.InteropServices.DispId(200)>]
[<get: System.Runtime.InteropServices.DispId(200)>]
member this.ElementID : string
Public ReadOnly Property ElementID As String

Property Value

A string representing the unique value for the element.

Attributes

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.

Applies to