How can I determine if an object can ToString into value or type name?
<p>I am writing an interop between a php service and our crm.  One of the things I need to do is make sure that simple types get converted ToString() for use later in a json converter.  </p>

<p>I am not sure even what the name is for 'simple types' but it can be defined like this... "an object that represents a low level variable type, containing a single value, not a class or anything with executable functions etc"</p>

<p>I've found that int, string, bool, double, and surprisingly enum will ToString() with pretty predictable results.</p>

<pre><code>int x = 0;
bool y = true;
double z = 1.59 // money
CustomEnum theEnum = CustomEnum.somevalue;
</code></pre>

<p>x.ToString() results in "0"</p>

<p>y.ToString() results in "true"</p>

<p>z.ToString() results in "1.59"</p>

<p>theEnum.ToString() results in "somevalue"</p>

<p>But if I use this:</p>

<pre><code>List&lt;int&gt; iList = new List&lt;int&gt;();
iList.Add(1);

MyClass theClass = new MyClass();
</code></pre>

<p>iList.ToString() results in "System.Collections.Generic.List`1[System.Int32]"
theClass.ToString() results in "STTI.NKI.Interop.MyClass"</p>

<p>I'm not limited to lists. I could have an ExpandoObject, or a class etc.</p>

<p>I understand EXACTLY why this happens, and I want to know if there is a quick way to determine if an object of unknown type will ToString() into an expected value, and not the type name.  I find it an antipattern to do something like</p>

<pre><code>switch (theObject.GetType())
 case typeof(int):
 case typeof(bool):
 case typeof(doulble):
etc
</code></pre>

<p>I am not sure what the terms are, so googling my answer is proving difficult. </p>