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. Serializable attribute!!! [modified]

Serializable attribute!!! [modified]

Scheduled Pinned Locked Moved C#
question
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.
  • H Offline
    H Offline
    Hussam Fattahi
    wrote on last edited by
    #1

    Is Serializable Attribute's behavior inheritable? i have two classes classA, classB. classA have Serializable attribute applied to it. classB inherits classA i want to serialize classB. do i have to apply serializable attribute to classB as well, or inherting from classA would be enough. thanks.

    modified on Sunday, September 7, 2008 9:23 AM

    W R 2 Replies Last reply
    0
    • H Hussam Fattahi

      Is Serializable Attribute's behavior inheritable? i have two classes classA, classB. classA have Serializable attribute applied to it. classB inherits classA i want to serialize classB. do i have to apply serializable attribute to classB as well, or inherting from classA would be enough. thanks.

      modified on Sunday, September 7, 2008 9:23 AM

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      You can use something like this to test your case:

      Stream stream = File.Open("serialized.xml", FileMode.Create);
      SoapFormatter formatter = new SoapFormatter();
      classB instanceB = new classB();
      formatter.Serialize(stream, instanceB);
      stream.Close();

      1 Reply Last reply
      0
      • H Hussam Fattahi

        Is Serializable Attribute's behavior inheritable? i have two classes classA, classB. classA have Serializable attribute applied to it. classB inherits classA i want to serialize classB. do i have to apply serializable attribute to classB as well, or inherting from classA would be enough. thanks.

        modified on Sunday, September 7, 2008 9:23 AM

        R Offline
        R Offline
        Robert C Cartaino
        wrote on last edited by
        #3

        The [Serializable] attribute is not inherited because your derived class might have fields that are not serializable. The author of your base class (who made the decision to make ClassA serializable) has no idea what you might add to ClassB. So the decision to make a class serializable (or not) is up to the class's author. Enjoy, Robert C. Cartaino

        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