Hi,
we have a problem when exporting data to excel or viewing data in grids.
For example, imagine a order with a CustomerId and order details. The
CustomerId maps to a concrete customer in Customers (with customer details,
such as name, etc.). The data object for this is implemented like the
following:
public class Order
{
public int CustomerId {get; set; }
// [...]
}
Now, I want to be able to wrap the data object Order when the order gets
exported like the following:
public class OrderView
{
public string Customer
{
get { // do some logic to get the requested value}
set { // do some logic to set the requested value }
}
}
whereas Customer returns the name of the customer. Of course it would be
easily to wrap the complete data object in such a manner that whenever an id
must be mapped to a name or else, we implement the requested logic, but when
it is not required we simply call the appropriate property in our data
object:
public class OrderView
{
private Order _Order;
public string Customer
{
get { // do some logic to get the requested value}
set { // do some logic to set the requested value }
}
public int Amount
{
get { return _Order.Amount; }
set { _Order.Amount = value; }
}
}
I heard of some methods using reflection (I think) where it is possible to
redefine properties. So what I am thinking of is to use this method to
overwrite properties whenever needed but to let through all other properties
with only little afford in coding whenever a property must not be
overwritten.
What is a good point to start here?
Regards,
Michael
|