Beispiel #1
0
    //********************************************************************************************
    //
    //********************************************************************************************

    public static bool Deserialize(ref T instance, Stream stream)
    {
        if (m_formatter == null)
        {
            return(false);
        }

        if (stream == null)
        {
            return(false);
        }

        SERIALIZATION.MODE smode = (SERIALIZATION.MODE)m_formatter.Deserialize(stream);

        if (smode == SERIALIZATION.MODE.DEFAULT)
        {
            instance = ( T )m_formatter.Deserialize(stream);
        }
        else
        {
            DeserializeMembers(instance, stream);
        }

        if (m_onDeserialized != null)
        {
            m_onDeserialized(instance);
        }

        return(true);
    }
Beispiel #2
0
    //********************************************************************************************
    //
    //********************************************************************************************

    public static bool Serialize(T instance, Stream stream, SERIALIZATION.MODE smode)
    {
        if (m_formatter == null)
        {
            return(false);
        }

        if (instance == null)
        {
            return(false);
        }

        if (stream == null)
        {
            return(false);
        }

        m_formatter.Serialize(stream, smode);

        if (smode == SERIALIZATION.MODE.DEFAULT)
        {
            m_formatter.Serialize(stream, instance);
        }
        else
        {
            SerializeMembers(instance, stream);
        }

        if (m_onSerialized != null)
        {
            m_onSerialized(instance);
        }

        return(true);
    }
Beispiel #3
0
    //********************************************************************************************
    //
    //********************************************************************************************

    public static bool Serialize(T instance, string filename, System.IO.FileMode fmode, SERIALIZATION.MODE smode)
    {
        if (m_formatter == null)
        {
            return(false);
        }

        if (instance == null)
        {
            return(false);
        }

        if (string.IsNullOrEmpty(filename))
        {
            return(false);
        }

        Stream stream = System.IO.File.Open(filename, fmode);

        bool result = Serialize(instance, stream, smode);

        if (stream != null)
        {
            stream.Close();
        }

        return(result);
    }