Using reflection in C# -
following this answer, i'm trying replicate , iterate on customermodel properties.
customermodel pippo = new customermodel(); type customer = pippo.gettype(); fieldinfo[] fields = customer.getfields(bindingflags.public | bindingflags.instance);
when using debugger, fields
has count = 0
customermodel has lot of public properties i'd see in fields. how can that? here's extract of properties declared i'd see.
[datamember] public string id { get; set; } [datamember] public string loginname { get; set; } [datamember] public string password { get; set; } [datamember] public string creationdate { get; set; }
perhaps binding flags incorrect? i'm new use of reflection.
those properties, not fields. use getproperties
instead of getfields
.
in c#:
public class foo { // field: private string _name; // property: public string name { get; set; } // property: public string somethingelse { { return _name; } set { _name = value; } } }
Comments
Post a Comment