title: Intercept method request and change parameter value
body: <p>I was able to create the following example:</p>
  
  <p><strong>ObservableClass</strong> </p>
  
  <pre><code>public class ObservableClass : MarshalByRefObject
  {
      public int DoSomething(int id, params string[] names)
      {
          return 1 + names.Length;
      }
  
      public int DoSomethingElse(int id, params string[] names)
      {
          return 1 + names.Length;
      }
  }
  </code></pre>
  
  <p><strong>Interceptor</strong></p>
  
  <pre><code>public class Interceptor : RealProxy
  {
      private readonly object _target;
  
      public Interceptor(object target) : base(target.GetType()) { _target = target; }
  
      public override IMessage Invoke(IMessage msg)
      {
          var methodCall = msg as IMethodCallMessage;
          return methodCall != null ? HandleMethodCall(methodCall) : null;
      }
  
      private IMessage HandleMethodCall(IMethodCallMessage methodCall)
      {
          try
          {
              var newArgs = methodCall.InArgs;
              if (methodCall.MethodName == "DoSomething")
              {
                  for (var i = 0; i &lt; newArgs.Length; i++)
                  {
                      if (methodCall.GetArgName(i) == "names")
                      {
                          newArgs[i] = new string[] { "a1", "a2", "a3", "a4" };
                      }
                  }
              }
              var result = methodCall.MethodBase.Invoke(_target, newArgs);
              return new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall);
          }
          catch (TargetInvocationException invocationException)
          {
              var exception = invocationException.InnerException;
              return new ReturnMessage(exception, methodCall);
          }
      }
  
      public static T Wrap&lt;T&gt;(T target) where T : MarshalByRefObject
      {
          return (T)new Interceptor(target).GetTransparentProxy();
      }
  }
  </code></pre>
  
  <p>And calling it by:</p>
  
  <pre><code>var temp = Interceptor.Wrap(new ObservableClass());
  var doSomethingRes = temp.DoSomething(1, "a", "b", "c");
  var doSomethingElseRes = temp.DoSomethingElse(1, "a", "b", "c");
  </code></pre>
  
  <p><strong>Output</strong>: doSomethingRes = 5, doSomethingElseRes = 4.</p>
  
  <p>This is working, however after some research I believe that the use of the <strong>MarshalByRefObject</strong> and the remote <strong>RealProxy</strong> will be extremely expensive for my real application scenario.</p>
  
  <p>I was wondering what other options (light and good performance) do I have to make something similar? </p>