您可以访问C#和实体框架中类的Scaffold属性吗?

您可以访问C#和实体框架中类的Scaffold属性吗?,c#,entity-framework,C#,Entity Framework,例如,如果你有 public class user { public string x { get; set; } [ScaffoldColumn(false)] public string y { get; set; } } 不管怎样,当我查看实体以确定y是否确实有脚手架列为false时,是否存在这种情况?我曾经尝试过这样的编程循环(伪代码): 但属性似乎没有属性属性,也没有指示属性(在本例中为y)是否为脚手架柱 在“user”的实现中,“x”和“y”不是属

例如,如果你有

 public class user 
 {
    public string x { get; set; }

    [ScaffoldColumn(false)]
    public string y { get; set; }
 }
不管怎样,当我查看实体以确定y是否确实有脚手架列为false时,是否存在这种情况?我曾经尝试过这样的编程循环(伪代码):


但属性似乎没有属性属性,也没有指示属性(在本例中为y)是否为脚手架柱

在“user”的实现中,“x”和“y”不是属性。如下所述实现它们,它们将出现在“GetProperties”集合中

public class user 
{
    public string x { get; set; }
    [ScaffoldColumn(false)]
    public string y { get; set; }
}

您可以获得所有具有
[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();
var props=obj.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.选择(p=>new
{
属性=p,
Attribute=p.GetCustomAttribute()
})
.Where(p=>p.Attribute!=null&&p.Attribute.Scaffold==false)
.ToList();

它们是。对不起,我用伪代码来证明概念。我将更新我的问题以反映这一点。See的作品非常迷人!非常感谢。
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();