Hi,
I would like solve the problem (now hypothetical but propably real in future) of using extension methods and maginification of class interface in future development.
Example:
/* the code written in 17. March 2010 */
public class MySpecialList : IList<MySpecialClass> {
// ... implementation
}
// ... somewhere elsewhere ...
MySpecialList list = GetMySpecialList(); // returns list of special classes
var reversedList = list.Reverse().ToList(); // .Reverse() is extension method
/* now the "list" is unchanged and "reveresedList" has same items in reversed order */
/* --- in future the interface of MySpecialList will be changed because of reason XYZ*/
/* the code written in some future */
public class MySpecialList : IList<MySpecialClass> {
// ... implementation
public MySpecialList Reverse() {
// reverse order of items in this collection
return this;
}
}
// ... somewhere elsewhere ...
MySpecialList list = GetMySpecialList(); // returns list of special classes
var reversedList = list.Reverse().ToList(); // .Reverse() was extension method but now is instance method and do something else !
/* now the "list" is reversed order of items and "reveresedList" has same items lake in "list" */
My question is: Is there some way how to prevent this case (I didn't find them)? If is now way how to prevent it, is there some way how to find possible issues like this? If is now way how to find possible issues, should I forbid usage of extension methods?
Thanks.
EDIT:
Yours answer was usefull. Can I found where in code are used extension methods? And/or can I found where in code are used instance methods but exists extension method with same signature?