about serializable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    about serializable

    Hello!

    Below you can see two different ways to create a BinaryFormatter to use when
    serialize object and collections.

    I know that BinaryFormatter implement IFormatter that's why you can use
    IFormatter in the way that is done here.

    IFormatter serializer = new BinaryFormatter ();
    BinaryFormatter serializer = new BinaryFormatter ();

    Now to my question assume I'm only interested in method Serialize and
    Deserialize which exist in IFormatter is it then
    better to use IFormatter as compile type instead of BinaryFormatter .

    So can I then say as a rule use the compile type that is most general and
    can access the methods.

    //Tony



  • Marc Gravell

    #2
    Re: about serializable

    In reality, you aren't likely to want to change the formatter and it
    isn't something you often need to be strategy-specific / factory
    based.

    I can't think of much benefit here - I'd just code against
    BinaryFormatter ; it is then clear what you are using... of course, if
    you genuinely have a need to use multiple binary formatters (perhaps
    you want to use "protocol buffers" ;-p) then code against IFormatter.

    (note to self: implement IFormatter on protobuf-net...?)

    Marc

    Comment

    Working...