lundi 7 septembre 2015

Object with properties Reflection Issue

I got the following situation, I have an object class having multiple properties.
This object is going to be used more than once for reporting purposes, however not all properties are needed, hence I was thinking of using attributes and reflection in order to be able to get the desired properties (for display binding purposes) when needed (instead of hardcoding which fields to use). I would like to use attributes and reflection in order to get the following functionality

What I had in mind is the following: - On each property set the DisplayName attribute (so far so good) - Set a custom property (Example: useInReport1,useInReport2.... which will be a boolean on each property)

I would like to know how I am able to achieve the custom properties [useInReport1], [useInReport2] etc.... + retrieve the fields needed only

Example of my object:

public class ReportObject
{
[DisplayName("Identity")]
 public int ID {get {return _id;}
[DisplayName("Income (Euros)")]
 public decimal Income {get {return _income;}
[DisplayName("Cost (Euros)")]
 public decimal Cost {get {return _cost;}
[DisplayName("Profit (Euros)")]
 public decimal Profit {get {return _profit;}
[DisplayName("Sales")]
 public int NumberOfSales {get {return _salesCount;}
[DisplayName("Unique Clients")]
 public int NumberOfDifferentClients {get {return _clientsCount;}
}





Aucun commentaire:

Enregistrer un commentaire