Detecting if class property is a reference type

前端 未结 7 620
广开言路
广开言路 2020-12-09 14:44

Is it possible when looking at a class\' properties to detect if any of them is a reference type.

Take below as an example:

public class Client
{
            


        
7条回答
  •  Happy的楠姐
    2020-12-09 15:25

    Check if the type is a string and check if it is a class.

            public static bool IsNonStringClass(this Type type)
            {
                if (type == null || type == typeof(string))
                    return false;
                return typeof(Type).IsClass;
            }
    

提交回复
热议问题