例如,如果你有
public class user
{
public string x { get; set; }
[ScaffoldColumn(false)]
public string y { get; set; }
}不管怎么说,当我看实体来判断y是否真的有脚手架列为false?我试过像这样通过编程循环(伪代码):
foreach(var prop in user.GetProperties())
{
var attributes = prop.Attributes;
}但是,似乎没有属性的属性,或指示属性(在本例中为y)是否为脚手架列。
发布于 2014-01-07 21:05:49
您可以获得所有具有如下[ScaffoldColumn(false)]的属性:
var props = obj.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Select(p => new
{
Property = p,
Attribute = p.GetCustomAttribute<ScaffoldColumnAttribute>()
})
.Where(p => p.Attribute != null && p.Attribute.Scaffold == false)
.ToList();发布于 2014-01-07 20:49:12
在用户的实现中,'x‘和'y’不是属性。按照下面的描述实现它们,它们将出现在“GetProperties”集合中
public class user
{
public string x { get; set; }
[ScaffoldColumn(false)]
public string y { get; set; }
}https://stackoverflow.com/questions/20981500
复制相似问题