相关疑难解决方法(0)

如何通过反射区分值类型,可空值类型,枚举,可空枚举,引用类型?

如何通过反射区分值类型,可空值类型,枚举,可空枚举,引用类型?

enum MyEnum
    {
        One,
        Two,
        Three
    }

    class MyClass
    {
        public int IntegerProp { get; set; }
        public int? NullableIntegerProp { get; set; }
        public MyEnum EnumProp { get; set; }
        public MyEnum? NullableEnumProp { get; set; }
        public MyClass ReferenceProp { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {   
            Type classType = typeof(MyClass);

            PropertyInfo propInfoOne = classType.GetProperty("IntegerProp");
            PropertyInfo propInfoTwo = classType.GetProperty("NullableIntegerProp");
            PropertyInfo propInfoThree = classType.GetProperty("EnumProp");
            PropertyInfo propInfoFour = classType.GetProperty("NullableEnumProp");
            PropertyInfo propInfoFive = classType.GetProperty("ReferenceProp");

            propInfoOne.??? …
Run Code Online (Sandbox Code Playgroud)

c# reflection propertyinfo

4
推荐指数
1
解决办法
2081
查看次数

标签 统计

c# ×1

propertyinfo ×1

reflection ×1