Open Miista opened 6 months ago
This would indeed be possible by adding the following code to Shim
.
public static Shim UnsafeReplace(MethodInfo method, bool setter = false)
{
return new Shim(method, method.DeclaringType) { _setter = setter };
}
The above supports both methods and properties. The UnsafeReplace
method would be used as follows:
var methodInfo = typeof(Class).GetMethod("PrivateMethod", BindingFlags.Instance | BindingFlags.NonPublic);
var with = Shim.UnsafeReplace(methodInfo).With((Class @this) => 100);
Please note, however, that this:
I cannot see a good reason for shimming private members. That is not to say that it won't be implemented.
Ref: https://github.com/tonerdo/pose/issues/57
Note that this would be incompatible with the changes in #13. Or at the very least it would introduce an alternate API.