title: Using delegates and MethodInfo to get method names for use in RPC calls in Photon
body: <p>In Photon, you can make RPC calls on a PhotonView (decorated with PunRPC) using <code>photonView("methodName", photonTargets, parameters[]);</code>, or <code>photonView("methodName", photonPlayer, parameters[]);</code></p>
  
  <p>One of the problems with this, having to use a string reference to a method, is lack of IDE support. Using something like ReSharper, I can generally navigate directly to a method definition using CTRL+B; that can't be done on just a string containing the method's name. My own laziness in not wanting to search for the methods manually aside, when multiple developers working on the same project are making RPC calls all over the place, from different classes, the confusion and frequent searches becomes a serious drain on willpower.</p>
  
  <p>What I was considering doing was creating extension methods for PhotonView to make RPC calls using a delegate instead of a string, and using that delegate to get the method name.</p>
  
  <p>Example:</p>
  
  <pre><code>    public static void CallRPC(
          this PhotonView photonView, 
          Action method,
          PhotonTargets photonTargets,
          params object[] parameters)
      {
          photonView.RPC(method.Method.Name, photonTargets, parameters);
      }
  
      public static void CallRPC&lt;T1&gt;(
          this PhotonView photonView,
          Action&lt;T1&gt; method,
          PhotonTargets photonTargets,
          params object[] parameters)
      {
          photonView.RPC(method.Method.Name, photonTargets, parameters);  
      }
  </code></pre>
  
  <p>Etc, covering PunRPC calls for methods of any foreseeable number of parameters (I use Action, because as far as I know, there aren't any RPC calls that can return a value, so any PunRPC methods we write should all return void).</p>
  
  <p>In this way, I get more IDE support, and can use CTRL+B to navigate to the method definition of the delegate. Also, no need to create string constants for all RPC method names.</p>
  
  <p>My question is, how would this impact performance? I see MethodInfo, and immediately assume some amount of reflection may be taking place. And assuming the performance hit is negligible, how about memory allocation? I vaguely recall reading somewhere that depending on how you use delegates, you may need to cache them, or risk additional allocations with each use.</p>
  
  <p>Is this viable, with little overhead? Or is there a better way?</p>