>>>I need to allow users to effectively 'sub-class' a .NET object at runtime. For example I have a graphics object with various properties (top, left, font etc). At runtime the user may need, in certain instances, to 'override' one ore more of these properties. These overrides can also be 'nested'.
>>>
>>>I'm looking for a good strategy, as generic as possible, for both storing and recreating these objects. Any suggestions? (I've a couple of avenues to explore but I'd appreciate any blue sky ideas...)
>>>
>
>>Viv,
>>I can't say I understood it exactly:) Anyway I'll try. Marking your type (maybe a shallow copy of it if not all) as serializable and serialize/deserialize it with BinaryFormatter would work?
>>Cetin
>
>Hi,
>
>Sorry - maybe I didn't explain enough. The 'sub-classed' object needs to inherit all non-overridden properties from the parent. Simple example, simple object:
>
>Parent:
>Top: 20
>Left: 20
>Font: Arial
>
>Say the user changes Left to 30. When the users version is saved and restored it should retain the change to the Left property but still pick up other fields from the parent so if, for example, the parent Right property is subsequenlt changed this will be reflected in the child since it was not overridden. (Just usual class hierarchy behaviour). I'm looking for a way to handle this with multiple levels of inheritance and in as generic a fashion as possible.
>
>I've done this in the past where the properties were stored as normalized data which was pretty straightforward - just used NULLS for inherited values and recursed thru the parent records. I could resort to this again but it may be better if it was handled at the object level...
>
>Regards,
>Viv
I see. Maybe PropertyInfoCollection could be applied somehow? Or another idea, during storage you might serialize one 'base' at top and add code to check 'overriden' properties?
VFP is storing overridden in 'properties' field. In the same manner you might add overriden ones to a namevaluecollection of the class? This one doesn't sound lead a generic code to me.
Cetin