C# monkey patching / concrete members overriding #8017
Replies: 6 comments 18 replies
-
I don't even think that this would be possible from within the language itself. You'd effectively have to rewrite the target assembly, which is well outside of what the compiler can or should do. |
Beta Was this translation helpful? Give feedback.
-
Can this be implemented with Source Generator & Interceptors ? |
Beta Was this translation helpful? Give feedback.
-
The solution here is dependency injection. Use interfaces. |
Beta Was this translation helpful? Give feedback.
-
This will invalidate one of the most important optimizations - inlining. Knowing something to be invariant is important, including method bodies, initialized-once values. |
Beta Was this translation helpful? Give feedback.
-
Take a look at libHarmony. We use the at for C# monkey patching and it works great. |
Beta Was this translation helpful? Give feedback.
-
You can not only try Harmony, but also give Jitex a try; it should be able to solve some of your problems. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
I want to propose well known monkey patching
I think it wont be used often in app code, however it will simplify writing tests / overriding sealed classes in libs
What is really important in development lifecycle.
I know there are libraries like Harmony / Microsoft Fake / MockType, however all of them are commercial and cumbersome.
It's also possible with Castle Windsor / Mock libs however in case of overriding exisitng library / nuget it's impossible with concrete not virtual class members
Usage:
Test.cs
This effect can be achieved in different manors, maybe even introduction of new keyword like force would be enough
Program.cs
Beta Was this translation helpful? Give feedback.
All reactions