[mono-vb] Default Indexers
Rolf Bjarne Kvinge
rolflists at ya.com
Fri Apr 9 12:25:03 EDT 2010
Hi,
I implemented it by looping over all the interfaces manually, the fix has
been committed.
Thanks a lot!
Rolf
> -----Mensaje original-----
> De: mono-vb-bounces at lists.ximian.com [mailto:mono-vb-
> bounces at lists.ximian.com] En nombre de John Lenz
> Enviado el: jueves, 08 de abril de 2010 20:32
> Para: mono-vb at lists.ximian.com
> Asunto: [mono-vb] Default Indexers
>
> Hi,
>
> The following code gives me VBNC30471 while MS.NET compiles it fine.
>
> Imports System.Data
>
> Public Class Main
>
> Public Shared Sub Main()
> Dim reader As IDataReader
> Dim a As Object
>
> a = reader(0)
> End Sub
>
> End Class
>
>
> 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
>
> http://anonsvn.mono-
> project.com/viewvc/trunk/mcs/class/System.Data/System.Data/IDataReader.
> cs
>
> http://anonsvn.mono-
> project.com/viewvc/trunk/mcs/class/System.Data/System.Data/IDataRecord.
> cs
>
> 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
>
> http://anonsvn.mono-
> project.com/viewvc/trunk/mcs/mcs/expression.cs?revision=152858#l8411
>
> http://anonsvn.mono-
> project.com/viewvc/trunk/mcs/mcs/typemanager.cs?revision=152808#l2354
>
> 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
> Next
>
> End If
>
> What do you think?
>
> John
> _______________________________________________
> Mono-vb mailing list
> Mono-vb at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-vb
More information about the Mono-vb
mailing list