What I want to do is something like this:
switch( myObject.GetType().GetProperty( "id") )
{
case ??:
// when Nullable<Int32>, do this
case ??:
// when string, do this
case ??:
// when Nullable<bool>, do this
What path under object.GetType() would have the string name of the datatype that I could compare using a case statement? I need to know the type so I can have one of many Convert.ToInt32( string ) that will set the value of myObject using Reflection.
Update: Looks like C# 7 will support switching on
Types as the asker of this question was trying to do. It’s a little different though so watch out for syntax landmines.You don’t need a string name to compare it: