2

For example if you have

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

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

Is there anyway, when I look at the entity to determine if y is indeed has scaffold column to false? I have tried looping through programatically like so (pseudo-code):

foreach(var prop in user.GetProperties())
{  
    var attributes = prop.Attributes;
}

but there seems to be no property attribute of the properties or to indicate weather the property (in this case y) is a scaffoldcolumn or not.

user3170736
  • 511
  • 5
  • 24

2 Answers2

1

You can get all the properties that have [ScaffoldColumn(false)] like this:

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();
Davor Zlotrg
  • 6,020
  • 2
  • 33
  • 51
0

In your implementation of 'user', 'x' and 'y' are not Properties. Implement them as described below and they will appear in the 'GetProperties' collection

public class user 
{
    public string x { get; set; }
    [ScaffoldColumn(false)]
    public string y { get; set; }
}
Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
  • 1
    They are. Sorry, I was using pseudo code to show a proof of concept. I will update my question to reflect that. – user3170736 Jan 07 '14 at 20:52