Hi
I have a requirement to copy an object at runtime. The object in question is a RadGridView (or more specifically an object inheriting RadGridView).
I know that cloning objects wasn't directly or easily achievable in the past, but I was wondering if the new reflection functionality would now make this possible.
Before I start experimenting, has anyone else had any experience/success in trying this? Or is there a better way to go about copying an object?
Thanks for any help.
Dave
|
Thanks, Mike.
You've confirmed my initial thoughts.
Well, you could also serialize the object and deserialize into a new instance.
Or you could implement/override a Clone() method in the class.
-.NET objects aren't guaranteed to have a Clone method, the ones that do and follow .NET best practices will also implement the IClonable interface.
- ABL objects will inherit one from Progress.Lang.Object, but you'll need to override it to add an actual implementation
Object serialization only works on objects that are marked as serializable. If just one object in that tree isn't, then it won't serialize properly.
Same with clonable objects. You'd have to check the whole object tree for the RadGridView and all the objects it uses to make sure they are all clonable/serializable.
This isn't a simple task to clone the whole object tree.
Better, is to move your object definition into something that is more appropriate to making multiple copies, such as an external file definition like JSON or XML, or to use a factory object with a generator that can configure multiple objects with the same setup.