Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Binary serialization questions

Binary serialization questions

Scheduled Pinned Locked Moved C#
jsonquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WujekSamoZlo
    wrote on last edited by
    #1

    I need to serialize object of my class. I derives from a class which is not serializable. The questions: 1) Do I have to implement the ISerializable interfaace in my class? 2) Are enums serializable?? I have several enum fields in my class. Thanks!

    K 1 Reply Last reply
    0
    • W WujekSamoZlo

      I need to serialize object of my class. I derives from a class which is not serializable. The questions: 1) Do I have to implement the ISerializable interfaace in my class? 2) Are enums serializable?? I have several enum fields in my class. Thanks!

      K Offline
      K Offline
      keith maddox
      wrote on last edited by
      #2

      #1 Just put the serializable attribute atop your class #2 Yes they are and will be automatically, if used in your serializable class the class you are deriving from not being serializable should not be a problem unless the class does some stuff that almost deliberlately makes it nonserializable. Give it a try, it should work flawlessly. Use the .NET serialization routines to save and restore your class, you'll find it works quite easily. Use the .NET Binary serializer in your main code to save/restore these class objects.

      M 1 Reply Last reply
      0
      • K keith maddox

        #1 Just put the serializable attribute atop your class #2 Yes they are and will be automatically, if used in your serializable class the class you are deriving from not being serializable should not be a problem unless the class does some stuff that almost deliberlately makes it nonserializable. Give it a try, it should work flawlessly. Use the .NET serialization routines to save and restore your class, you'll find it works quite easily. Use the .NET Binary serializer in your main code to save/restore these class objects.

        M Offline
        M Offline
        Mathew Hall
        wrote on last edited by
        #3

        #1 Just put the serializable attribute atop your class That won't work if the class he's extending is not serializable. From the MSDN[^]: "It is important to note that the Serializable attribute cannot be inherited. If you derive a new class from MyObject, the new class must be marked with the attribute as well, or it cannot be serialized. For example, when you attempt to serialize an instance of the class below, you will get a SerializationException informing you that the MyStuff type is not marked as serializable". The only way around it is to use ISerializable "I think I speak on behalf of everyone here when I say huh?" - Buffy

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups