How to decide a Type is a custom struct?

前端 未结 6 1407
谎友^
谎友^ 2020-12-18 20:14

For a Type, there is a property IsClass in C#, but how to decide a Type is a struct?

Although IsValueType is a ne

6条回答
  •  无人及你
    2020-12-18 21:02

    Should be at least

    bool isStruct = type.IsValueType && !type.IsEnum &&
                   !type.IsPrimitive && type != typeof(decimal);
    

提交回复
热议问题