Exemple #1
0
        /// <summary>
        /// Gets properties
        /// </summary>
        /// <param name="properties">Properties</param>
        /// <param name="bytes">Bytes</param>
        /// <returns>Properties</returns>
        public static object GetProperties(object properties, byte[] bytes)
        {
            if (properties != null)
            {
                return(properties);
            }
            if (bytes == null)
            {
                return(null);
            }
            if (bytes.Length == 0)
            {
                return(null);
            }
            try
            {
                object obj = StaticExtensionSerializationInterface.Deserialize <object>(bytes);
                if (obj != null)
                {
                    return(obj);
                }
            }
            catch (Exception)
            {
            }
            MemoryStream    ms = new MemoryStream(bytes);
            BinaryFormatter bf = new BinaryFormatter();

            return(bf.Deserialize(ms));
        }
Exemple #2
0
        /// <summary>
        /// Gets object from bytes
        /// </summary>
        /// <typeparam name="T">Type of object</typeparam>
        /// <param name="obj">The object</param>
        /// <param name="bytes">Bytes</param>
        /// <returns>The object</returns>
        public static T GetObject <T>(ref T obj, byte[] bytes) where T : class
        {
            if (obj != null)
            {
                return(obj);
            }
            if (bytes == null)
            {
                return(null);
            }
            if (bytes.Length == 0)
            {
                return(null);
            }
            try
            {
                obj = StaticExtensionSerializationInterface.Deserialize <T>(bytes);
                if (obj != null)
                {
                    return(obj);
                }
            }
            catch (Exception ee)
            {
                ee.ShowError(10);
            }
            MemoryStream        ms     = new MemoryStream(bytes);
            BinaryFormatter     bf     = new BinaryFormatter();
            SerializationBinder binder = StaticExtensionSerializationInterface.Binder;

            if (binder == null)
            {
                try
                {
                    obj = bf.Deserialize(ms) as T;
                }
                catch (Exception ex)
                {
                    ex.ShowError(10);
                    return(null);
                }
            }
            else
            {
                try
                {
                    bf.Binder = binder;
                    obj       = bf.Deserialize(ms) as T;
                }
                catch (Exception exc)
                {
                    exc.ShowError(10);
                    return(null);
                }
            }
            return(obj);
        }