Exemplo n.º 1
0
 /// <summary>
 /// Make this object suitable to be the Global context
 /// </summary>
 public void ResetToGlobalDefault()
 {
     m_fieldRenamer = null;
     m_parent       = null;
     ClearExternalSurrogates();
     ResetToDefaults();
 }
Exemplo n.º 2
0
        /// <summary>
        /// This helper will turn an object into a properly formatted XML document, as a string.
        /// </summary>
        /// <param name="_object">The object to turn into a string</param>
        /// <param name="_context">The Serialization Context to use, if the default one won't work.</param>
        /// <returns>The object serialized as a string-form XML document</returns>
        public static string ToString(object _object, CSerializationContext _context = null)
        {
            var ser = new CSerializer(_context);
            var xml = ser.Serialize(_object);

            xml.DocumentElement.Attributes.RemoveAll();
            var str = new StringWriter();

            xml.Save(str);
            return(str.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieve a deserialized object from a file
        /// </summary>
        /// <typeparam name="T">The Type of the object that is to be deserialized</typeparam>
        /// <param name="_filename">The name of the file that contains the information for deserialization</param>
        /// <param name="_context">Serialization context for the operation</param>
        /// <returns>The object that was deserialized</returns>
        public static T FromFile <T>(string _filename, CSerializationContext _context = null)
        {
            var d = new CDeserializer(_context);

            return(FromFile <T>(_filename, d));
        }
Exemplo n.º 4
0
        /// <summary>
        /// This helper will use a default CSerializer to serialize an object to a named file. It will overwrite that file.
        /// It will use a specified <see cref="CSerializationContext"/> to control the serialization
        /// </summary>
        /// <param name="_object">The object to serializat</param>
        /// <param name="_filename">The name of the file to save the serialized object to</param>
        /// <param name="_context">The Serialization Context to use for the serialization</param>
        public static void ToFile(object _object, string _filename, CSerializationContext _context = null)
        {
            var s = new CSerializer(_context);

            ToFile(_object, _filename, s);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Construct with a default context object
 /// </summary>
 /// <param name="_context">The context object to use for the serialization</param>
 public CSerializer(CSerializationContext _context)
     : base(_context)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Construct a CSerialization context that inherits values from some other context.
 /// </summary>
 /// <remarks>
 /// This is generally used by the framework, but since an application could use this as well, it is
 /// marked public rather than internal.
 /// </remarks>
 /// <param name="_parent">The context to inherit</param>
 public CSerializationContext(CSerializationContext _parent)
 {
     m_parent = _parent;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Default constructor for a serialization context
 /// </summary>
 public CSerializationContext()
 {
     m_parent = Global;
 }