Persisting Custom Objects

3 posts, 0 answers
  1. Mark
    Mark avatar
    44 posts
    Member since:
    Jun 2009

    Posted 22 Nov 2011 Link to this post

    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. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 23 Nov 2011 Link to this post

    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Mark
    Mark avatar
    44 posts
    Member since:
    Jun 2009

    Posted 23 Nov 2011 Link to this post

    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
Back to Top