Formatter class implementation

I'm looking for information or a sample of how to implementing a Formatter derived class. I would like to implement a custom formatter and would like to know how to make use of the Formatter class functionality.

Thanks,
Ray



Answer this question

Formatter class implementation

  • Anvar

    Thanks Vikram but I wasn't looking to implement IMessageFormatter. I want to implement a System.Runtime.Serialization.Formatter class and would like to know how to make use of the base class functionality. In particular I'd like to see the Schedule() and GetNext() methods in action as well as well as how to make use of the m_objectQueue during deserialization.

    A couple other pieces to the puzzle are why does this class implement all the Write* routines I'm guessing they are there because there are helper routines somewhere that makes use of these functions by iterating through the serializable fields and it's likely that is the bit of code that enforces the serialization rules but where is that functionality I suspect you call GetNext() and send the returned object to that code for serialization and it in turn calls the Serialization.Formatter.

    Thanks,
    Ray



  • toypaj

    Hi,

    I guess the only option for you then would be to go through the source code of the .NET Framework [ROTOR].

    Take look at the implementation of the Formatter Class.
    http://dotnet.di.unipi.it/Content/sscli/docs/doxygen/fx/bcl/classSerialization_1_1Formatter.html

    Hope this helps.

    Regards,
    Vikram

  • SCHRANK

  • bobberino1

    I just posted a summary of the steps required to design a custom IFormatter (part of those information already appear in my previous posts in this newsgroup).

    Regards,
    Joannes

  • JenLS

    Yes, I've already looked at that sample and it still does not answer the question. It implements IFormatter but does not implement the Formatter class. The formatter class as documented "Provides base functionality for the common language runtime serialization formatters". Which extends the IFormatter interface.

    Obviously the person who wrote the gotdotnet sample was aware of the Formatter class since he implemented his own queue and used the same function names as the Formatter class. My guess is that he was also not able to find information on how to make use of the Formatter class.

    Perhaps a bit more detail about the glue I'm missing is in order (pseudo code):

    class MyFormatter: Formatter
    {
       Serialize(object o)
       {
          Schedule(o);

          While(o = GetNext())
          {
             // something goes here that iterates the object members and 
             //   calls the appropriate Formatter.Write* routines and places 
             //   object references in the queue. My belief is that some helper
             //   takes my formatter object and implements that functionality
             //   calling my Formatter.Write* routines as needed while enforcing
             //   serialization rules -- what/where is it  If such a helper does not, 
             //   exist, then Formatter class is nothing more than a named queue and 
             //   really provides little to no functionality.
          }
       }

       Deserialize()
       {
             // what goes here to reconstruct the references , Formatter contains
             // contains the Write* routines, is there another object that is supposed
             // to provide an interface to a set of Read* routines that I would 
             // implement
       }
    }


    Thanks,
    Ray

  • Viktor Placek

  • Formatter class implementation