G
Guest
I have a base class that has been filled with values (for example an Order)
So, something like this
dim ord as new Order(
ord.FirstName = "Clayton
ord.LastName = "Gulick
etc..
Now, I have a derived class called InternalOrder, that extends Order
How can I force the above order into the InternalOrder class
I know, the first question is "Why? Thats bad design!
There is a method to my madness, namely that I want to expose the Order class to customers via a web service. I want this class to be trim and simple, and I don't want the guts of our internal variables to show to the world
However, when an Order is submitted from the Web Service, I need to stick it into InternalOrder so I can do some additional processing on it and fill additional internal values (for example, integrate with legacy system etc...
It is painful to have to write all the code to manually copy all the properties down to the InternalOrder class
The only thing I can think to do is to use reflection and enumerate through all the properties and copy all of the public ones over. This gets sticky though because I would have to recursively navigate the Order to also copy all of the sub-object properties (Address, BillingInfo etc...)
Sure would be nice if I could do something like
dim ord as new Order(
dim IntOrd as new InternalOrder(
IntOrd = ForceCast(ord, InternalOrder
If not, I'll go ahead and write a generic static ForceCast class and post the code, but I am hoping there is a better way.
So, something like this
dim ord as new Order(
ord.FirstName = "Clayton
ord.LastName = "Gulick
etc..
Now, I have a derived class called InternalOrder, that extends Order
How can I force the above order into the InternalOrder class
I know, the first question is "Why? Thats bad design!
There is a method to my madness, namely that I want to expose the Order class to customers via a web service. I want this class to be trim and simple, and I don't want the guts of our internal variables to show to the world
However, when an Order is submitted from the Web Service, I need to stick it into InternalOrder so I can do some additional processing on it and fill additional internal values (for example, integrate with legacy system etc...
It is painful to have to write all the code to manually copy all the properties down to the InternalOrder class
The only thing I can think to do is to use reflection and enumerate through all the properties and copy all of the public ones over. This gets sticky though because I would have to recursively navigate the Order to also copy all of the sub-object properties (Address, BillingInfo etc...)
Sure would be nice if I could do something like
dim ord as new Order(
dim IntOrd as new InternalOrder(
IntOrd = ForceCast(ord, InternalOrder
If not, I'll go ahead and write a generic static ForceCast class and post the code, but I am hoping there is a better way.