locked
Serialization RRS feed

  • Question

  • Hi. I have a class which is not serializable but i need to serialize it in the other classes. It's possible to do for instance by name but i don't want to write additional methods in each class. Maybe there is some framework which can help in such situation? Thanks.
    Thursday, July 25, 2013 5:15 AM

Answers

All replies

  • Maybe you could do a wrapper class that is serializable and serialize your non-serializable class with that.

    Thursday, July 25, 2013 5:30 AM
  • It's possible but wrapper class is additional thing which demands maintaining and testing. Now i'm wondering if it's possible to solve that task without wrappers.
    Thursday, July 25, 2013 8:42 PM
  • Hello, According to your description, I know that you encounter some issue about serialization,you can refer this article:http://msdn.microsoft.com/en-us/library/Vstudio/ms233843.aspx

    In addition, I think you can do like this:

    //A  class which is not serializable 
    Class A
    {
      //define some member of A class including properity and menthod
    } 
    //AA class which is a agent class that can serialize A
    Class AA
    {
      //declare a object  obj of A class
      //serialize the member of obj
       serializeA(A obj);
      
    }
    // B class and C class can serialize A class through AA class
    Class B
    {
        //declare a  object of AA class  and then call serializeA(A obj);
    }
    Class C
    {
       //declare a  object of AA class and then call serializeA(A obj) 
    }


    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, July 25, 2013 10:09 PM
  • It's wrapper. I'm wondering about a framework which allows serialize not serializable objects.
    Friday, July 26, 2013 5:22 AM
  • The .NET Framework allows you to serialize objects that are not marked as [Serializable]. However you have to write some code instead of wrapper. See an example: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.surrogateselector.aspx.

    Saturday, July 27, 2013 7:18 AM
  • Looks good but the problem is i need xml serialization.
    Saturday, July 27, 2013 3:53 PM
  • Looks good but the problem is i need xml serialization.

    Then use XmlSerializer to serialize your class directly, taking into consideration the limitations described in documentation.

    Saturday, July 27, 2013 5:16 PM
  • Then use XmlSerializer to serialize your class directly, taking into consideration the limitations described in documentation.

    Unfortunately i'm using it.
    Saturday, July 27, 2013 8:38 PM
  • Hi Booster1,

    Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know.

    Have a great day!

    Best Regards,


    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 30, 2013 8:29 AM
  • Maybe i haven't explained clear enough. I need xml serialization for not serializable objects and i don't want to wrap them and i don't want to write additional code in the classes where these objects are located. I'd like to register these objects and to set rules how to serialize them, that's all. Maybe i need specific serializer. Probably i can write it myself but maybe there is such one already.
    • Edited by Booster1 Tuesday, July 30, 2013 8:53 PM edit
    Tuesday, July 30, 2013 4:10 PM
  • Hi Booster1,

    According to your description, you want to register some objects and to set rules how to serialize them,I suggest you to use Custom Serialization  .

    Custom Serialization Example: http://www.codeproject.com/Articles/22787/Custom-Serialization-Example

    In addition , you can try to  use XML Schema Definition Tool (Xsd.exe), which generates XML schema or common language runtime classes from XDR, XML, and XSD files, or from classes in a runtime assembly.you can refer this sample: Simplifying Serialization and De-serialization Processes With XSD.EXE

    Hope these help,have a nice day.

    Best Regards,


    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, July 31, 2013 5:26 AM
  • Thank you Lilia. Some of your links are dead for me. I know about interface ISerializable but it demands to write some code into each serializable class what i want to avoid.
    Friday, August 2, 2013 5:15 PM
  • Maybe show an object (or a simple example that is similar to your case) that cannot be serialized by XmlSerializer.

    Friday, August 2, 2013 5:45 PM
  • For instance we have array of predefined objects. Each has id. And we have another array. Each element of that one has reference into object from the first one. We need serialize second array.
    Friday, August 2, 2013 6:26 PM
  • Hello Booster1,

    Thank you for your reply.

    I'm deeply sorry for  the trouble  we cause you work ,I have correct the answer.

    Hope these help,have a nice day.


    Best Regards,
    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 7, 2013 7:08 AM