C# Reflection: How to get the type of a Nullable?

后端 未结 5 1344
面向向阳花
面向向阳花 2021-01-01 11:04

What I want to do is something like this:

switch( myObject.GetType().GetProperty( \"id\") )
{
    case ??: 
        // when Nullable, do this
           


        
5条回答
  •  萌比男神i
    2021-01-01 11:25

    As @Cody Gray said if statements would probably be the best way

    var t = myObject.GetType();
    
    if (t == typeof(Nullable))
    { }
    else if (t == typeof(string))
    {}
    else if (t==typeof(Nullable))
    {}
    

提交回复
热议问题