Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving to generics .

I am migrating a 1.1 winforms app to 2.0. what are the main things i should immediately change because of generics. Here what i have so far:

  1. Replace all hashtables with generic dictionaries
  2. Replace all arraylists with List<>
  3. Replace all CollectionBase derive classes with : List<>

Any others that should be done immediately?

thks, ak

like image 777
leora Avatar asked Nov 29 '08 15:11

leora


2 Answers

I don't think anything should be done immediately! The 1.1 code works, right? What's the business case for the wholesale swap to generics? Compile the app under 2.0, get it running and tested. And then, as new features are needed that would let you exploit generics well, implement those features as generics.

like image 57
rp. Avatar answered Oct 04 '22 18:10

rp.


Any others that should be done immediately?

Generally, change any mention of IEnumerable to IEnumerable<T>, where possible. Migration can be greatly helped by switching the whole namespace, i.e. un-importing System.Collections in every file and instead importing System.Collections.Generic.

Also, search for mentions of object and/or usage of boxing in your code and consider whether this is still appropriate or should be replaced by generics.

As jalf reminded me in the comments, another important change is the switch to the generic version of IComparable where applicable.

like image 36
Konrad Rudolph Avatar answered Oct 04 '22 19:10

Konrad Rudolph