Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see a way where you can determine this at runtime for any given type. The only way to accomplish this would be to create collection with all known types that have your desired behaviour. That woould be the built-in value type like <code>int</code>, <code>double</code> and so on + the reference type <code>string</code>.</p> <p>As I mentioned in the comments you cannot just check for the type's <code>IsValueType</code> property because this would be <code>true</code> for <code>struct</code>'s but <code>struct</code>'s itself can contain objects. Consider the following code:</p> <pre><code>class Program { static void Main(string[] args) { var dataTable = new DataTable(); dataTable.Columns.Add("ABC", typeof(string)); var a = new CustomStruct() { IntValue = 1, DataTable = dataTable }; Console.WriteLine("IsValueType: {0}", a.GetType().IsValueType); Console.WriteLine(); var b = a; a.IntValue = 2; a.DataTable.Columns.Add("DEF", typeof(int)); Console.WriteLine("a.IntValue: {0}", a.IntValue); Console.WriteLine("a.DataTable.Columns.Count: {0}", a.DataTable.Columns.Count); Console.WriteLine(); Console.WriteLine("b.IntValue: {0}", b.IntValue); Console.WriteLine("b.DataTable.Columns.Count: {0}", b.DataTable.Columns.Count); } } public struct CustomStruct { public int IntValue; public DataTable DataTable; } </code></pre> <p>The output is:</p> <pre><code>IsValueType: True a.IntValue: 2 a.DataTable.Columns.Count: 2 b.IntValue: 1 b.DataTable.Columns.Count: 2 </code></pre> <p>So you see, though <code>CustomStruct</code> is a value type <code>b</code>'s <code>DataTable</code> object is the same as <code>a</code>'s.</p> <p>So creating a custom list with know types with the desired behaviour is the easiest way to go.</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