Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not possible without parsing the code in question.</p> <p>At runtime only two pieces of type information are available, the <em>actual</em> type of a value (via object.GetType()) and, if the variable in question is a parameter or class/instance variable the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.fieldinfo.fieldtype.aspx" rel="nofollow noreferrer">FieldType</a> property on a FieldInfo, <a href="http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.propertytype.aspx" rel="nofollow noreferrer">PropertyType</a> on a PropertyInfo or <a href="http://msdn.microsoft.com/en-us/library/system.reflection.parameterinfo.parametertype.aspx" rel="nofollow noreferrer">ParameterType</a> on a ParameterInfo.</p> <p>Since the value passed to you may well have come via several variables on its route to you the question is not even well defined I'm afraid.</p> <p>Ah - I see you want only the type as currently defined in the method, the Expression functionality will provide this (Roman's answer shows a neat way to do this) but beware trying to use this outside the method... In essence you are letting the generic type inference of the compiler infer the type in question but this means that the variable used is <em>not</em> always the variable you can see. It may instead be that of a compiler synthesised variable, for example:</p> <pre><code>string x = "x"; Console.WriteLine(x.GetDeclaredType()); // string Console.WriteLine(((object)x).GetDeclaredType()); // object </code></pre> <p>Since the compiler synthesises a temporary variable in which to place an object reference to x.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload