This is a migrated thread and some comments may be shown as answers.

Persisting Custom Objects

2 Answers 88 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 22 Nov 2011, 05:02 PM
Hello,

I am trying to use the Persistence Framework to persist a custom object, and am hoping to confirm some of the behaviour that I am seeing.

If I do not specify a custom property provider for my type, I observe the following:

  • Only properties that are primitive types get persisted.
  • However, nullable types are not supported.  You cannot return null for ProvideValue.
  • Properties that are complex types (i.e. other classes) do not get persisted.
  • Implementing ISerializable my classes (top-level or property classes) makes no difference!  (I.e. ISerializable.GetObjectData never gets called.)

 

If I do specify a custom property provider, I observe the following:

 

  • Only properties returned in GetCustomProperties get persisted.  This means, that I need to specify (and support) every property that I want persisted - even ones of primitive types.
  • For complex properties, I can create proxy objects to be saved.  But if these property types themselves have complex properties, it seems I need to package up the entire property tree in the proxy for my top-level property.  Is this true??!
  • Again, implementing ISerializable makes no difference as it never gets called.  This would be a nice way to serialize deep property structures as described in the previous point.

Since the persistence framework has a method that returns a Stream for a particular object, it surprises me that implementing ISerializable on the object I wish to persist does not help.  Am I missing something? 

Finally, if you cannot implement ISerializable, how do you go about persisting deep structures using the custom property provider? 

If someone could help clarify these observations, and perhaps offer a suggeestion about these deep property structures, that would be great!!

Thanks,
Mark

2 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 23 Nov 2011, 03:58 PM
Hi Mark,

The Persistence Framework is designed (by default) to persist only the UI-related properties of the ui elements in an applicaation. It does not try to persist custom objects (which might be a DataContext or ItemsSource). The ISerializable interface is not taken into consideration, while serializing an object, but this is a nice suggestion and we are going to consider integrating it.

However, you are still able to persist a custom object with the framework. This can be done by overriding the GetSerializer method of the PersistenceManager class and using the Serializer class, instead of the UISerializer.

public class MyPersistenceManager : PersistenceManager
{
    protected override Telerik.Windows.Persistence.Serialization.ISerializer GetSerializerOverride()
    {
        return new Serializer(this);
    }
}
This serializer will try to save and load all of the properties of an object - collections, primitive, complex, etc. properties.

Please let me know if that would work in your scenario.

Best wishes,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mark
Top achievements
Rank 1
answered on 23 Nov 2011, 04:57 PM
Hi Alex,

Thanks for your quick response and great suggestion.  I have managed to find a workaround for my immediate need through a custom property provider, but I think your idea of a custom serializer may work well too.  I may try this approach when I have more time for testing (as we are on the brink of finalizing a release).

Thanks again,
Mark
Tags
PersistenceFramework
Asked by
Mark
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or