Contents tagged with MSIL

  • Mocking constructor

    While unit testing a target type, it is likely that the test is failing during object creation because we forgot to include a mandatory configuration file or a line in the constructor is throwing exception because it is making call to some external service or data store which on the other hand requires a little more orchestration to get things going . To better illustrate this, let’s create an entity framework data container either new or from an existing database. Once we have completed the required steps, there will be an entry-point class where we will notice the following default constructor:

  • Creating a basic proxy for intercepting [quick update].

    In my previous post, i enhanced the proxy to support generic calls. In order to minimize IL emit and move more parts to managed code, there is a better way to process the return value rather doing the checks against runtime method and see whether the method’s return type is a value or not for generic calls to un-box the object form that is returned from the interceptor.

  • A basic proxy for intercepting method calls (Part – 3)

    In my previous posts, I showed how to create a proxy that can delegate calls. I further modified it to support argument list from original method and handled scenarios for void and non-void calls. In this post, i will further enhance it to introduce generic calls.

  • A basic proxy for intercepting method calls (Part –2)

    In my previous post , i introduced a basic proxy that intercepts methods. But what is missing in the proxy is that it does not consider method arguments and can not handle return types. In this post, i will enhance the proxy to support exactly those.

  • A basic proxy for intercepting method calls (Part –1)

    In this post, i am going to show how you can write your own proxy for delegating calls. This just shows a way how you can handle it on your own but for complex interceptions its always wise to use alpha/beta/tested solutions. The post is more of an under the hood or aims to solve simple interception tasks where you might not need a full featured dynamic proxy or can be useful in building something that requires similar techniques which can move you further.