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
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...