带反射的GetProperties也应返回Nullable <t>

时间:2017-10-18 13:13:26

标签: c# linq

我正在阅读特定类型List<T>实体的所有属性。

除了Nullable<int>

,我得到了我想要的所有属性
var properties = entities.GetType().GetGenericArguments().Single()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where( p => Type.GetTypeCode(p.PropertyType) != TypeCode.Object).ToList();

如何更改查询以获取Nullable<T>类型?

2 个答案:

答案 0 :(得分:1)

public class GetAddressInfoResponse : ApiResponse { // ErrorCode supplied from base // ErrorMessage supplied from base public AddressInfo AddressInfo { get; set; } } 将计为Nullable<T>,因此您需要更改查询:

TypeCode.Object

答案 1 :(得分:0)

<header>