Simple Generics should be CLS Compiliant

G

Guest

Currently, generic types are not CLS compliant. This puts library authors in
a quandry who are faced with three bad alternatives:
1. CLS Compliance but no generics,
2. Using generic types but losing CLS Compliance, or
3. Supporting both, bloating the code and muddying the waters with dual
versions of generic classes.
This latter is seen in mscorlib with collections classes, Nullable, and
EventHandler as examples.

I believe there is a simple alternative. Allow simple generic types -- those
with at most base class constraints -- to be consumable by any CLS language.
How? Since not all languages can specify the generic parameters, have these
default to the base class constraint.

Imagine generic List is accessed from a language with no support for
generics. List<UNSPECIFIED> is interpreted as List<object>. Isn't that
equivalent to ARRAY_LIST? Isn't Dictionary<object,object> the same as
Hashtable? Isn't EventHandler<EventArgs> the same as EventHandler? Have the
CLI interpret older tokens of newly-generic types in this way.

This schema renders the non-generic variants unnecessary. So let's get rid
of them, using these simple generics. This provides one simple GENERIC way to
create new types, even if I want them to be generic *and* referenceable from
any .NET language (i.e. CLS compliant).

This is the subject of my suggestion FDBK39498. Personally, I think this is
pretty important. Please have a look there and make your vote.
(http://lab.msdn.microsoft.com/ProductFeedback/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top