I would like to replace a class at the assembly level so all references call a new implementation. Lets say I have common class used in assemblies throughout my project such as
System.Generic.Collections.List
My project references other assemblies who rely on List as well.
Now lets say I want to use my version of List Where ever this is called.
var values = new List<int> { 1, 2, 3, 4, 5 }
How can replace a class on the assembly level so I don't have to update any references in my code or so that it can be done in a single location.
I remember there are metadata buddy classes and things like that is it possible to override using a global pragma? I vaguely remember using syntax like this for something: System.Generic.Collections.List::MyAssembly.List
I would like to replace this in a duck-typed way where the underly class doesn't nessecarily have to inherit from the original but I should have all the methods exposed in the same manner
Note: I need to resolve this in a global manner, a single entry point via reflection or configuration.
I've already done things in the past to dynamically replace methods, see: Dynamically Append Code to a method .Net-Core
This is going to cause maintenance confusion and headache down the road. The closest thing I know of to what you are asking for is a
using alias.However, my recommendation whenever possible is to just use a different name for your classes. It's more clear and keeps your code maintainable. Somewhere down the road, someone (possibly you) is going to look at your List that's not a System.Generic.Collections.List and get really confused.
You can, however, have your custom list implement IList, which is a preferred approach.