You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have meet such situation:
I need to Shim private static method. But your framework could not do it, because Shim.Replace could not understande reflection.
But I have found solution: var _newShim = (Shim) typeof(Shim) .GetConstructor( BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] {typeof(MethodBase), typeof(object)}, null) .Invoke( new object[] { typeof(TestClass) .GetMethods(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod) .Single(m => m.Name == privateMethodName), null }); _newShim.With(delegate(int val) { return val + 1; });
It will be much easy if Shim have got public constructor.
The text was updated successfully, but these errors were encountered:
@InsonusK In the current implementation it's only possible to shim public members. I understand you would like the option to shim private (and possibly also internal and protected) members.
In its current form, the library uses expressions to resolve the method/property. This gives us a strongly typed way to verify the method-to-shim and its replacement.
Non-public members cannot (by definition) be resolved via expressions. We would therefore have to give up some of the strong typing to support this.
Hello, I am using your framework.
I have meet such situation:
I need to Shim private static method. But your framework could not do it, because Shim.Replace could not understande reflection.
But I have found solution:
var _newShim = (Shim) typeof(Shim) .GetConstructor( BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] {typeof(MethodBase), typeof(object)}, null) .Invoke( new object[] { typeof(TestClass) .GetMethods(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod) .Single(m => m.Name == privateMethodName), null }); _newShim.With(delegate(int val) { return val + 1; });
It will be much easy if Shim have got public constructor.
The text was updated successfully, but these errors were encountered: