Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CodeProperty.Parent is not always a class

5 views
Skip to first unread message

Carlos J. Quintero

unread,
Sep 20, 2002, 4:13:54 AM9/20/02
to
I have found an issue with the CodeProperty.Parent property of the VS.Net
extensibility model. According with the model, CodeProperty.Parent returns a
EnvDTE.CodeClass instead of a EnvDTE.CodeElement. But the parent of a
Property can be a Structure or an Interface, and in this cause you can not
get the parent using that property.

To reproduce it (VS.Net final version, no Net framework SP installed):

1) Create a VB.Net add-in, with the default options but indicating to the
wizard to create a button in the Tools menu.

2) Inside the Exec procedure on the connect.vb file, merge this code:

Dim objTextSelection As TextSelection
Dim objCodeElement As CodeElement
Dim objCodeProperty As CodeProperty
Dim objObject As Object

Try
objTextSelection = CType(applicationObject.ActiveDocument.Selection,
TextSelection)
objCodeElement =
applicationObject.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPo
int(objTextSelection.ActivePoint, vsCMElement.vsCMElementProperty)

objCodeProperty = CType(objCodeElement, CodeProperty)

' According to the extensibility model, the parent of a CodeProperty is
a CodeClass.
' But it can happen that the parent is an Interface or Structure,
causing an exception here:
objObject = objCodeProperty.Parent
If TypeOf objObject Is CodeElement Then
MsgBox("The parent name is: " & CType(objObject, CodeElement).Name)
End If

Catch e As Exception
MsgBox(e.Message)
End Try

3) Run the add-in project. A new VS.Net instance is loaded.

4) Insert in Form1.vb this code:

Private Class Class1
Property Property1() As String
Get
End Get
Set(ByVal Value As String)
End Set
End Property
End Class

Interface Interface1
Property Property2() As String
End Interface

4) Put the cursor on the line "Property1" and click the add-in button. You
get the parent name of "Property1" which is "Class1"
5) Put the cursor on the line "Property2" and click the add-in button. You
get an exception "Interface not compatible" or similar.

I know that you can still get the parent using a top to down navegation
using the code elements hierarchy, but it seems to me a flaw in the
extensibility model. Comments?

Carlos


Visual Studio Core Team [MS]

unread,
Sep 23, 2002, 6:38:54 PM9/23/02
to
Very sorry, this is a design flaw that we missed before shipping. We are
looking at correcting this in a future release.

Thanks,
Bill

--
This posting is provided "AS IS" with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation. All rights reserved.


"Carlos J. Quintero" <carlos_j_quinter...@hotmail.com> wrote
in message news:#BUBs1HYCHA.428@tkmsftngp11...

0 new messages