[Mono-dev] System.Reflection and C# compiler differences between Mono and .NET.
Jonathan Pryor
jonpryor at vt.edu
Fri Jun 8 07:46:34 EDT 2007
Mono's (g)mcs produces different metadata for explicitly-implemented
interface members than CSC does. Thus, a question:
Should these differences be considered to be Mono bugs?
Details:
Consider explicitly implemented methods and properties:
using System.Collections;
using System.Collections.Generic;
class Demo : IEnumerator, IEnumerator<Demo>,
IEnumerable<Demo>, IEnumerable
{
/* ... unimportant ... */
// explicitly implemented interface members
object IEnumerator.Current {
get { return null; }
}
Demo IEnumerator<Demo>.Current {
get { return null; }
}
IEnumerator IEnumerable.GetEnumerator ()
{
return null;
}
IEnumerator<Demo> IEnumerable<Demo>.GetEnumerator ()
{
return null;
}
}
There are two significant differences between Mono's behavior and .NET's
behavior.
1. Property names: (g)mcs generates TypeName.MemberName, while CSC
produces Namespace.TypeName.MemberName, e.g. IEnumerator.Current vs.
System.Collections.IEnumerator.Current.
Oddly, (g)mcs generates Namespace.TypeName.MemberName for methods; it's
only properties that get abbreviated in this fashion.
2. Generics: gmcs produces significantly different member names compared
to CSC:
gmcs: System.Collections.Generic.IEnumerable`1[[Foo, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].GetEnumerator
CSC: System.Collections.Generic.IEnumerator<Foo>.Current
As you can see, generic parameter handling is quite different --
<Foo> vs. `1[[Foo, test, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null]]. The same generic parameter handling difference
exists for properties as well as methods.
This difference is somewhat important because it's user-visible: you can
use System.Type.GetMember(string, BindingFlags) to load
explicitly-implemented interface members on a given type, but to do so
you need to use the *same* name as is present within the assemblies
metadata. Consequently, this means that different strings must be used
to obtain the same member depending on whether the assembly was compiled
by CSC or gmcs (the Mono/.NET runtime is irrelevant).
Again, the question: Should these differences be considered bugs within
Mono?
Thanks,
- Jon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo.cs
Type: text/x-csharp
Size: 1757 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070608/8ed39849/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo-gmcs.il
Type: text/x-csrc
Size: 13567 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070608/8ed39849/attachment-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo-csc.il
Type: text/x-csrc
Size: 14686 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070608/8ed39849/attachment-0002.bin
More information about the Mono-devel-list
mailing list