Possibly save 2 hours of your time: There are times when you want to refactor your method. This happens when you have duplicate code that acts on two similar objects.
- You have ObjectA
- You have ObjectB
- You have Method1(ObjectA)
- You have Method2(ObjectB)
- Both Method1 and Method2 has exact code that operates on the similar Object.
- First, make ObjectA and ObjectB inherit same interface IObject
class ObjectA : IObject
class ObjectB : IObject
- Then, change your Method1 and Method2 to
Method<T>(T object) where T : IObject
- Third, refactor your method 1 and 2 so that your caller will just call this method with ObjectA or ObjectB as parameter