Skip to content

Commit c4e00c1

Browse files
committed
Added support for constructors
1 parent a9b7c25 commit c4e00c1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/DllManipulator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ private static void Initialize()
104104
{
105105
if (_options.mockCallsInAllTypes || type.IsDefined(typeof(MockNativeCallsAttribute)))
106106
{
107-
foreach (var method in type.GetRuntimeMethods())
107+
foreach (var method in type.GetRuntimeMethods().Cast<MethodBase>()
108+
.Concat(type.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)))
108109
{
109110
if (!(method is DynamicMethod) && method.DeclaringType == type && method.GetMethodBody() != null)
110111
{
@@ -200,8 +201,7 @@ private static IEnumerable<CodeInstruction> CallingMethodTranspiler(IEnumerable<
200201
{
201202
if (instr.opcode == OpCodes.Call)
202203
{
203-
var nativeMethod = (MethodInfo)instr.operand;
204-
if (_nativeFunctionsToMock.Contains(nativeMethod))
204+
if (instr.operand is MethodInfo nativeMethod && _nativeFunctionsToMock.Contains(nativeMethod))
205205
{
206206
if (!_nativeCallMocks.TryGetValue(nativeMethod, out var newMethod))
207207
{

0 commit comments

Comments
 (0)