title: Deserialize a string from the uri template to an operation Type parameter
body: <p>I have this restfull service that I want to be able to call for all classes in a certain namespace or assembly. And I'm going to need to know for which Type it is called inside the operation. In short I want a template that allows both of these:</p>
  
  <pre><code>../MyClass1/some/further/spec
  ../MyClass2/some/further/spec
  </code></pre>
  
  <p>I want my uri templates to look something like this:</p>
  
  <pre><code>/{type}/some/further/{info}
  </code></pre>
  
  <p>And my operation will be something like this:</p>
  
  <pre><code>public void ClassSpecificOfSomeFurtherSpec(Type type, string info)
  </code></pre>
  
  <p>I'm assuming there's no way to do anything like the following, which I guess is what I'm really trying to achieve. After all, generics have to be decided at compile time I guess. But it illuminates the problem:</p>
  
  <pre><code>public void ClassSpecificOfSomeFurtherSpec&lt;type&gt;(string info)
  </code></pre>
  
  <p>The problem here is that the input for class is a the short Name of a Type, rather than the FullName, which means Type.GetType(class, true, true) won't work. If it would I could use that in my custom deserialization, and everything would be fine. But since it won't, I'm reluctant to hardcode my namespace into my generic deserialization, since it would make it utterly non-generic.</p>
  
  <p>If I were to add an IParameterInspector, could I then modify the parameter (or only inspect it), and tack on the namespace before the deserialization takes place, or will the order be the other way around?</p>
  
  <p>I've got this feeling that I'm overcomplicating things. Is there a no-brainer way to do this sort of thing that I've missed, or some really convincing reason why I shouldn't generalize my services this much?</p>
  
  <p>Bottom line is that I want to avoid this sort of code for every single operation:</p>
  
  <pre><code>public Response ClassSpecificOfSomeFurtherSpec(string type, string spec)
  {
      Type theType = Type.GetType("My.NameSpaced."+type, true, true);
      //.. and the stuff that does things
  }
  </code></pre>
  
  <p>Update1</p>
  
  <p>So, I found this nice <a href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/12/wcf-extensibility-ioperationbehavior.aspx" rel="nofollow" title="blog post">blog post</a> by Carlos describing how to add the option of turning an IParameterInspector into an improved version that can also modify parameters. In the blog he only modifies return values. What I wanted to do was modify the input value. So, I added that capability and added my modifier class:</p>
  
  <pre><code>public class EntityParameterModifier : IParameterModifier
  {
      public OperationDescription Description { get; private set; }
  
      public EntityParameterModifier(OperationDescription description)
      {
          Description = description;
      }
  
      public object BeforeCall(string operationName, ref object[] inputs)
      {
          var parts = Description.Messages[0].Body.Parts;
          for (int i = 0; i &lt; parts.Count; i++)
          {
              if (parts[i].Type == typeof(Type) &amp;&amp; inputs[i].GetType() == typeof(string))
                  inputs[i] = EntityStringToType((string)inputs[i]);
          }
  
          return null;
      }
  
      public void AfterCall(string operationName, object[] outputs, ref object returnValue, object correlationState) { }
  
      private Type EntityStringToType(string entityString)
      {
          Assembly assembly = Assembly.GetAssembly(typeof(Entity));
          Type type = (from t in assembly.GetTypes()
                       where t.Name == entityString || t.FullName == entityString
                       select t).SingleOrDefault&lt;Type&gt;();
          return type;
      }
  }
  </code></pre>
  
  <p>But, of course they've added some blocks to prevent you from doing this sort of thing:</p>
  
  <pre><code>[InvalidOperationException: Operation 'ClassSpecificOfSomeFurtherSpec' in contract 
  'IMyServiceContract' has a path variable named 'type' which does not have type 'string'.
  Variables for UriTemplate path segments must have type 'string'.]
  System.ServiceModel.Dispatcher.UriTemplateClientFormatter.Populate(Dictionary`2&amp; pathMapping, Dictionary`2&amp; queryMapping, Int32&amp; totalNumUTVars, UriTemplate&amp; uriTemplate, OperationDescription operationDescription, QueryStringConverter qsc, String contractName) +1128
  </code></pre>
  
  <p>Which points me in a completely new direction. Is there any way to override the UriTemplateClientFormatter or related classes to achieve what I want?</p>