I have a large project which was originally written in C#1.1 and is now targeting C#2.0. There are several classes which have methods which take an ArrayList parameter I would like to start to move these to accept List<T>
as a parameter, but this can't be done all at one time, so I need to accept both parameters.
My main reason for the migration is so that List<>
objects will be accepted as parameters, but I would also like to take advantage of type safety.
Have considered
1) Creating overloads and duplicating the code. This has the advantage of allowing me to mark the old style code as obsolete, but obviously duplicating code is bad.
2) Changing the parameter to IEnumerable :
This has the advantage of working with both old and new code, but is not type-safe as it will accept List<T1>
where it should be List<T2>
3) Re-writing the methods to take a List<T>
parameter and writing a thin wrapper which takes an ArrayList parameter and copies the items to a new List<T>
and then calls the main method. This also has the advantage of allowing me to mark the old style code as obsolete. It will have a slight performance/GC hit.
4) Creating three overloads. One private method which take IEnumerable and two public wrapper methods (one for ArrayList and one for List<T>
) which just call the private method.
This also has the advantage of allowing me to mark the old style code as obsolete. Not sure whether it has any dis-advantages other than having three methods.
I am leaning towards 4, but am I overlooking anything?