Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>System.RuntimeType</code> is a concrete class that derives from the abstract base class <code>System.Type</code>. Since <code>System.RuntimeType</code> is not public, you will typically encounter instances of it as <code>System.Type</code>.</p> <p>Confusion can arise when you are trying to get the type of an object and mistakenly call <code>GetType()</code> on another object representing the first object's type, rather than just using that object directly. Then <code>Type.ToString()</code> will return <code>"System.RuntimeType"</code> when the object it is called on is representing a Type:</p> <pre><code>string str = string.Empty; Type strType = str.GetType(); Type strTypeType = strType.GetType(); strType.ToString(); // returns "System.string" strTypeType.ToString(); // returns "System.RuntimeType" </code></pre> <p>For example, in <a href="http://doogalbellend.blogspot.com/2006/06/what-is-systemruntimetype.html">this blog post</a> someone is trying to get the type of a column in a database, doing something like this:</p> <pre><code>object val = reader.GetFieldType(index); Type runtimeType = val.GetType(); PropertyInfo propInfo = runtimeType.GetProperty("UnderlyingSystemType"); Type type = (Type)propInfo.GetValue(val, null); </code></pre> <p>Since val is already a Type object, val.GetType() will return another Type object representing the type <code>System.RuntimeTime</code> as this is the concrete type used to represent the original type object. The blog post then shows some unnecessary reflection trickery, to get the type of the original type object, when really all that was required was:</p> <pre><code>Type type = reader.GetFieldType(index) as Type; </code></pre> <p>So if your <code>Type</code> object is reporting that it represents a <code>System.RuntimeType</code>, make sure you have not accidentally called <code>GetType()</code> on a type you have already got.</p>
 

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