This enables seamless integration with all the LINQ goodness, rather than
being forced (and usually forgetting) to invoke collection.Cast<T> on all
collections before using them in queries.

I preserved the existing enumerators logic, basically just using the
following pattern:

- Existing enumerator (on some collections):
public new IEnumerator GetEnumerator ()
{
return this.BaseGetAllValues ().GetEnumerator ();
}

- Replaced with:
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator();
}

public new IEnumerator<TypeReference> GetEnumerator()
{
foreach (var item in this.BaseGetAllValues())
{
yield return (TypeDefinition)item;
}
}


This preserves the existing code that is using the non-generic enumerator
(via "foreach") while exposing the new typed enumerator by default. If you
think the visibility should be the other way around (public untyped
enumerator and privately implemented typed enumerator) just let me know and
I can make the change and submit a new patch.

For classes directly inheriting from CollectionBase which didn't have a
specialized enumerator, I simply added:

public new IEnumerator<EventDefinition> GetEnumerator()
{
foreach (var item in this.List)
{
yield return (EventDefinition)item;
}
}

Attached is the patch.
I think all such collections should basically dissapear now that we have
generics, but I didn't want to make the change bigger than needed. I just
wanted the LINQ-enabled API, and IEnumerable<T> is the minimum requirement
for it.

Thanks!

-- 
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1
425.329.3471

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Attachment: Mono.Cecil-all collections implement IEnumerable of T.patch
Description: Binary data

Reply via email to