[Mono-dev] Generic type naming

David Mitchell dave at fallingcanbedeadly.com
Fri Mar 9 20:41:37 EST 2007


You're right...there's no difference in the implementation for the names of
Generic types. The weirdness in the type name that I was seeing comes from
using the fancy new 'yield return' syntax that was introduced in C# 2.0.

To illustrate, try this block of code in Mono and on .NET:

--------------------------
using System;
using System.Collections.Generic;
using System.Collections;

namespace MonoBug
{
	public class ListBug
	{
		public static IEnumerable<T> EnumerableFromArray<T>(T[]
array)
		{
			foreach (T t in array)
				yield return t;
		}

		public static IEnumerable<int> IntEnumerableFromArray(int[]
array)
		{
			foreach (int i in array)
				yield return i;
		}

		public static void Main()
		{
			Console.WriteLine(EnumerableFromArray(new int[] { 1,
2, 3 }).GetType());
			Console.WriteLine(IntEnumerableFromArray(new int[] {
1, 2, 3 }).GetType());
		}
	}
}
--------------------------
You'll get different results on each platform, although I'm not entirely
certain if the naming convention is part of the C# spec or not. I'm looking
into this because I'm trying to get all of the Wintellect.PowerCollections
tests to succeed in Mono (http://www.wintellect.com/PowerCollections.aspx).

If you download it right now, four of the tests will fail, and the first one
does so because the test makes assumptions about the type name.

--Dave

-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Robert Jordan
Sent: Monday, March 05, 2007 11:26 PM
To: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-dev] Generic type naming

David Mitchell wrote:
> My apologies if I am dredging up an issue that has already been resolved
and
> put to rest, but my curiosity compels me to do so.
> 
>  
> 
> I have noticed that Mono's algorithms for providing names to specific
> generic types is significantly different to that of Microsoft's
> implementation of .Net. Where Microsoft's implementation usually has lots
of
> fancy angle brackets and full type listings of the arguments, Mono often
has
> weird accent marks and numbers.

Like Mono, MS uses the accent marks as well. For example,
Dictionary`2[K, T] denotes the non-instantiated generic type
Dictionary<K, T> (C# notation), whereas Dictionary`2[[String, Int32]]
is an instantiated Dictionary<string, int> (C# notation).

When full names are requested, the type names become ever weirder:

System.Collections.Generic.Dictionary`2
[
	[
		System.String, mscorlib,
		Version=2.0.0.0, Culture=neutral,
		PublicKeyToken=b77a5c561934e089
	],
	[
		System.Int32, mscorlib, Version=2.0.0.0,
		Culture=neutral, PublicKeyToken=b77a5c561934e089
	]
]

> Is this difference between the two implementations the result of an
> architectural decision, developer laziness (hey, the best developers are
all
> a bit lazy, right?), or of something in between the two extremes?

There should be no differences. Please file bugs if you find some.

Robert

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list