Type.FullName returns malformed name

  • Thread starter Thread starter George
  • Start date Start date
G

George

I declared an enumeration inside an interface. Trying to use reflection to
find the FullName of the enumeration type produces

"WindowsApplication1.IGeorge+GeorgeConstants"

rather than

"WindowsApplication1.IGeorge.GeorgeConstants"

as I (and the rest of the framework) would expect.


My code is as follows (start a new VB Windows app, add the Interface and the
call to Msgbox into the Form_Load, hit F5):

Public Interface IGeorge
Enum GeorgeConstants
GeorgeConstant1
GeorgeConstant2
GeorgeConstant3
End Enum
End Interface

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
:
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MsgBox(GetType(IGeorge.GeorgeConstants).FullName)
End Sub

End Class


George.
 
I declared an enumeration inside an interface. Trying to use reflection to
find the FullName of the enumeration type produces

"WindowsApplication1.IGeorge+GeorgeConstants"

rather than

"WindowsApplication1.IGeorge.GeorgeConstants"

as I (and the rest of the framework) would expect.


Reflection uses + as the delimiter between a nested class and its
encloser. Nothing wrong there.



Mattias
 
* "George said:
I declared an enumeration inside an interface. Trying to use reflection to
find the FullName of the enumeration type produces

"WindowsApplication1.IGeorge+GeorgeConstants"

rather than

"WindowsApplication1.IGeorge.GeorgeConstants"

as I (and the rest of the framework) would expect.


My code is as follows (start a new VB Windows app, add the Interface and the
call to Msgbox into the Form_Load, hit F5):

Public Interface IGeorge
Enum GeorgeConstants
GeorgeConstant1
GeorgeConstant2
GeorgeConstant3
End Enum
End Interface

Notice that the type 'GeorgeConstants' is defined /inside/ 'IGeorge', so
it's a nested type. Nested types are indicated with a "+" separator
instead of ".". If you don't want 'GeorgeConstants' to be a nested
type, take its code and place it somewhere outside your interface.
 
Thanks, I've now read up about the (many) delimiters. I never realised there
were so many. Makes sense once you know why though.

The problem occurred in a third party grid product that was bound to a
DataTable containing a field of an Enum type. When the grid tried to convert
its display value to the underlying enum type it used reflection to get the
target type and then some sort of conversion procedure which doesn't
understand the '+'. I've changed my code to use the underlying primitive
type in the DataTable (Int32 for Enum types), pending a fix from the third
party.

George
 
Back
Top