我试图在下面的类型中获取所有公共属性。 在.NET框架我倒是要通过使用IsPublic
从PropertyInfo
类型,但似乎并不在.NET的核心存在2.NET Core 2.0中的PropertyInfo.IsPublic的等价物
internal class TestViewModel
{
public string PropertyOne { get; set; }
public string PropertyTwo { get; set; }
}
//how can I retrieve an IEnumerable with PropertyOne and PropertyTwo ONLY?
var type = typeof(TestViewModel);
var properties = type.GetProperties().Where(p => /*p.IsPublic &&*/ !p.IsSpecialName);
@mjwills不是重复,因为有这么回答建议TypeExtensions,不与.NET核2.0(apparantly)工作。 – NullBy7e
@mjwills我在这里犯了错,我编辑了这个问题并使其更加清晰。 – NullBy7e