I am refactoring a C# library that uses a Dictionary<int, SomeInterface> all over the system.
I need to change the key type from int to string, and use a Dictionary<string, SomeInterface> instead, and I am making dozens of changes.
How to do it better, how to define a type in one place and uses it everywhere, so that if I need to change it later, I can change it in one place?
I already added a GetKey() method to my interface.
Edit: the library is used in other DLLs, and I want to limit possible changes to only one library. This is an agile shop, so we need to be ready for changes.
If swapping the type of key is important to you, consider a custom class wrapping the underlying key.
e.g, public class Key { public Key(object adaptee) { ... } }
Remember to implement Equals() and GetHashCode() and just delegate to the underlying object.
I'm not sure if this helps your particular scenario, but in general, Resharper is a fantastic tool to help assist with these types of changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With