[mono-vb] Default Indexers
jlenz2 at math.uiuc.edu
Thu Apr 8 14:31:31 EDT 2010
The following code gives me VBNC30471 while MS.NET compiles it fine.
Public Class Main
Public Shared Sub Main()
Dim reader As IDataReader
Dim a As Object
a = reader(0)
I traced the problem down to Helper.vb line 1560:
System.Attribute.GetCustomAttribute(Type, GetType(DefaultMemberAttribute), True)
When Type is System.Data.IDataReader this call returns Nothing. The issue is that the default
indexer is actually declared on IDataRecord, see
The problem is that if you look at the code for GetCustomAttribute it does not check base classes
for the DefaultMemberAttribute even though you pass True. (The inherit flag is reset to false in
MonoCustomAttrs.cs::GetCustomAttributes() because the attribute does not have the
AttributeUsage.Inherited flag). Therefore when searching for the DefaultMemberAttribute on
IDataReader nothing is found.
I looked at what gmcs does and the closest thing I could find is in expression.cs line 8411
Looking at the IndexerPropertyName() function in typemanager.cs, it seems like gmcs just uses a name
of "Item" if it can't find anything. I am not sure if that is the correct behavior for VB.
Perhaps we should just manually check base classes for DefaultMemberAttribute since
GetCustomAttribute does not do it. Something like
Dim defAttr As Type = GetType(DefaultMemberAttribute)
attr = Attribute.GetCustomAttribute(Type, defAttr)
If attr Is Nothing Then
For Each t As Type in Type.GetInterfaces()
attr = Attribute.GetCustomAttribute(t, defAttr)
If attr IsNot Nothing Then Exit For
What do you think?
More information about the Mono-vb