title: How to access custom attributes defined in WCF service using C#?
body: <p>First question is, how can I get the type of an object stored in a variable? Generally we do: </p>
  
  <pre><code>Type t = typeof(ClassName); //if I know the class
  </code></pre>
  
  <p>but, how can I say something:</p>
  
  <pre><code>Type t = typeof(varClassName); //if the class name is stored in a variable
  </code></pre>
  
  <p>Second question, a broader picture is, I have a WCF service that contains a DataContract class say "MyClass" and I have defined a custom attribute called "MyAttribute" to it. There is one method say "GetDataUsingDataContract" with a parameter of type MyClass. Now on client, I invoke the webservice. I use MethodInfo and ParameterInfo classes to get the parameters of the method in question. But how can I access the attributes of the method parameter which is actually a class Myclass? Here is the code that I tried:</p>
  
  <pre><code>MyService.Service1Client client = new MyService.Service1Client();
  Type t = typeof(MyService.Service1Client);
  MethodInfo members = t.GetMethod("GetDataUsingDataContract");
  ParameterInfo[] parameters = members.GetParameters();
  foreach (var parameter in parameters)
  {
       MemberInfo mi = parameter.ParameterType; //Not sure if this the way
       object[] attributes;
       attributes = mi.GetCustomAttributes(true);
  }
  </code></pre>
  
  <p>Above code doesn't retrieve me the custom attribute "MyAttribute". I tried the concept in the class that is defined in the same project and it works. Please HELP!</p>