title: CRM 2011 One Plugin for Multiple Entities
body: <p>I am writing a plugin which will essentially perform the same function - say, create a task when the status changes. The functionality needs to happen on 2 entities. </p>
  
  <p>Every step is exactly the same except setting of the Entity Type field (an Option Set). This is set to <code>EntityA</code> or <code>EntityB</code> depending upon which entity triggered the plugin. </p>
  
  <p>My existing code does the following</p>
  
  <pre class="lang-cs prettyprint-override"><code>new_entitya entityA = (context.InputParameters.Contains("Target") &amp;&amp; context.InputParameters["Target"] is Entity &amp;&amp; context.PrimaryEntityName == "new_entitya")
                                      ? ((Entity)context.InputParameters["Target"]).ToEntity&lt;new_entitya&gt;()
                                      : null;
  </code></pre>
  
  <p>Now, is there a way that I can set the value of .ToEntity call based on the value of PrimaryEntityName instead of writing new_entitya or new_entityb?</p>