System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(System.IO.Stream)

Here are the examples of the csharp api System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(System.IO.Stream) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

693 Examples 7

19 View Source File : Utils.cs
License : GNU General Public License v3.0
Project Creator : 2dust

public static T DeepCopy<T>(T obj)
        {
            object retval;
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                //序列化成流
                bf.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                //反序列化成对象
                retval = bf.Deserialize(ms);
                ms.Close();
            }
            return (T)retval;
        }

19 View Source File : EncodingUtil.cs
License : MIT License
Project Creator : 404Lcc

public static object DeserializationDecode(byte[] bytes)
        {
            object obj;
            using (MemoryStream stream = new MemoryStream(bytes))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                obj = formatter.Deserialize(stream);
            }
            return obj;
        }

19 View Source File : ObjectSerializationExtension.cs
License : MIT License
Project Creator : 734843327

public static T Deserialize<T>(this byte[] byteArray) where T : clreplaced
		{
			if (byteArray == null)
			{
				return null;
			}
			using (var memStream = new MemoryStream())
			{
				var binForm = new BinaryFormatter();
				memStream.Write(byteArray, 0, byteArray.Length);
				memStream.Seek(0, SeekOrigin.Begin);
				var obj = (T)binForm.Deserialize(memStream);
				return obj;
			}
		}

19 View Source File : FrmMain.cs
License : MIT License
Project Creator : A-Tabeshfard

[Obsolete]
        private void MnuFileNew_Click(object sender, EventArgs e)
        {
            _frmContent = new();
            _frmContent.MdiParent = this;
            _frmContent.Text = "Note Pad - " + MdiChildren.Length.ToString();
            _frmContent.Show();

            if (File.Exists("FormatConfiguration_Font.bin"))
            {
                FileStream ConfigFile = new("FormatConfiguration_Font.bin", FileMode.Open);
                BinaryFormatter Deserializer = new();
                FormatConfiguration Current = Deserializer.Deserialize(ConfigFile) as FormatConfiguration;
                ConfigFile.Close();
                ((FrmContent)ActiveMdiChild).textBox.Font = Current.CurrentFont;
            }

            if (File.Exists("FormatConfiguration_BackColor.bin"))
            {
                FileStream ConfigFile = new("FormatConfiguration_BackColor.bin", FileMode.Open);
                BinaryFormatter Deserializer = new();
                FormatConfiguration Current = Deserializer.Deserialize(ConfigFile) as FormatConfiguration;
                ConfigFile.Close();
                ((FrmContent)ActiveMdiChild).textBox.BackColor = Current.CurrentColor;
            }

            if (File.Exists("FormatConfiguration_ForeColor.bin"))
            {
                FileStream ConfigFile = new("FormatConfiguration_ForeColor.bin", FileMode.Open);
                BinaryFormatter Deserializer = new();
                FormatConfiguration Current = Deserializer.Deserialize(ConfigFile) as FormatConfiguration;
                ConfigFile.Close();
                ((FrmContent)ActiveMdiChild).textBox.ForeColor = Current.CurrentColor;
            }
        }

19 View Source File : Program.cs
License : Apache License 2.0
Project Creator : AantCoder

static void Main(string[] args)
        {
            var workPort = args == null || args.Length < 2 ? 0 : int.Parse(args[1]);
            var workPath = @"C:\World" + (workPort == 0 ? "" : "\\" + workPort.ToString());

            var SaveFileName = Path.Combine(workPath, "World.dat");
            var SaveFileNameOld = Path.Combine(workPath, "WorldOld.dat");
    
            if (!File.Exists(SaveFileName)) 
            {
                return;
            }

            File.Copy(SaveFileName, SaveFileNameOld, true);

            BaseContainer Data;
            using (var fs = File.OpenRead(SaveFileName))
            {
                var bf = new BinaryFormatter();
                Data = (BaseContainer)bf.Deserialize(fs);
            }

            //тут будет код конвертации, если понадобиться


            using (var fs = File.OpenWrite(SaveFileName))
            {
                var bf = new BinaryFormatter();
                bf.Serialize(fs, Data);
            }
        }

19 View Source File : GZip.cs
License : Apache License 2.0
Project Creator : AantCoder

public static object Deserialize(byte[] bytes)
        {
            using (var msi = new MemoryStream(bytes))
            {
                if (formatter == null) formatter = new BinaryFormatter();
                return formatter.Deserialize(msi);
            }
        }

19 View Source File : Repository.cs
License : Apache License 2.0
Project Creator : AantCoder

public void Load()
        {
            bool needResave = false;
            if (!Directory.Exists(SaveFolderDataPlayers))
                Directory.CreateDirectory(SaveFolderDataPlayers);
            if (!File.Exists(SaveFileName))
            {
                Data = new BaseContainer();
                Save();
                Loger.Log("Server Create Data");
            }
            else
            {
                using (var fs = File.OpenRead(SaveFileName))
                {
                    var bf = new BinaryFormatter() { Binder = new ServerCoreSerializationBinder() };
                    Loger.Log("Server Load...");
                    Data = (BaseContainer)bf.Deserialize(fs);
                    //var dataVersion = Data.VersionNum;
                    Loger.Log("Server Version data: " + Data.Version + " Current version: " + MainHelper.VersionInfo);

                    if (Data.Version != MainHelper.VersionInfo || Data.VersionNum < MainHelper.VersionNum + 1)
                    {
                        convertToLastVersion();
                        needResave = true;
                    }

                    if (Data.Orders == null) Data.Orders = new List<OrderTrade>();

                    Data.UpdatePlayersAllDic();

                    Loger.Log("Server Load done. Users " + Data.PlayersAll.Count.ToString() + ": "
                        + Data.PlayersAll.Select(p => p.Public.Login).Aggregate((string)null, (r, i) => (r == null ? "" : r + ", ") + i)
                        );

                    ChatManager.Instance.NewChatManager(Data.MaxIdChat, Data.PlayerSystem.Chats.Keys.First());
                }
            }


            if (needResave)
                Save();
            ChangeData = false;


        }

19 View Source File : RandomWeaponGeneratorWindow.cs
License : MIT License
Project Creator : Abdelfattah-Radwan

private void LoadreplacedetReferences()
		{
			templates?.Clear();
			weaponBases?.Clear();
			stocks?.Clear();
			grips?.Clear();
			magazines?.Clear();
			scopes?.Clear();
			barrels?.Clear();

			string filePath = Path.Combine("Temp", replacedET_REFERENCES_INSTANCE_IDS_FILE_NAME);

			if (File.Exists(filePath))
			{
				List<int>[] lists = new List<int>[0];

				using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
				{
					lists = new BinaryFormatter().Deserialize(fileStream) as List<int>[];
				}

				lists[0].ForEach(id => templates?.Add(replacedetDatabase.LoadreplacedetAtPath<WeaponPropertiesTemplate>(replacedetDatabase.GetreplacedetPath(id))));
				lists[1].ForEach(id => weaponBases?.Add(replacedetDatabase.LoadreplacedetAtPath<WeaponBase>(replacedetDatabase.GetreplacedetPath(id))));
				lists[2].ForEach(id => stocks?.Add(replacedetDatabase.LoadreplacedetAtPath<GameObject>(replacedetDatabase.GetreplacedetPath(id))));
				lists[3].ForEach(id => grips?.Add(replacedetDatabase.LoadreplacedetAtPath<GameObject>(replacedetDatabase.GetreplacedetPath(id))));
				lists[4].ForEach(id => magazines?.Add(replacedetDatabase.LoadreplacedetAtPath<GameObject>(replacedetDatabase.GetreplacedetPath(id))));
				lists[5].ForEach(id => scopes?.Add(replacedetDatabase.LoadreplacedetAtPath<GameObject>(replacedetDatabase.GetreplacedetPath(id))));
				lists[6].ForEach(id => barrels?.Add(replacedetDatabase.LoadreplacedetAtPath<GameObject>(replacedetDatabase.GetreplacedetPath(id))));
			}
		}

19 View Source File : FileCacheManager.cs
License : Apache License 2.0
Project Creator : acarteas

protected virtual object DeserializePayloadData(string fileName, SerializationBinder objectBinder = null)
        {
            object data = null;
            if (File.Exists(fileName))
            {
                using (FileStream stream = GetStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFormatter formatter = new BinaryFormatter();

                    //AC: From http://spazzarama.com//2009/06/25/binary-deserialize-unable-to-find-replacedembly/
                    //    Needed to deserialize custom objects
                    if (objectBinder != null)
                    {
                        //take supplied binder over default binder
                        formatter.Binder = objectBinder;
                    }
                    else if (Binder != null)
                    {
                        formatter.Binder = Binder;
                    }
                    try
                    {
                        data = formatter.Deserialize(stream);
                    }
                    catch (SerializationException)
                    {
                        data = null;
                    }
                }
            }

            return data;
        }

19 View Source File : FileCacheManager.cs
License : Apache License 2.0
Project Creator : acarteas

protected virtual object Deserialize(string fileName, SerializationBinder objectBinder = null)
        {
            object data = null;
            if (File.Exists(fileName))
            {
                using (FileStream stream = GetStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFormatter formatter = new BinaryFormatter();

                    //AC: From http://spazzarama.com//2009/06/25/binary-deserialize-unable-to-find-replacedembly/
                    //    Needed to deserialize custom objects
                    if (objectBinder != null)
                    {
                        //take supplied binder over default binder
                        formatter.Binder = objectBinder;
                    }
                    else if (Binder != null)
                    {
                        formatter.Binder = Binder;
                    }
                    try
                    {
                        data = formatter.Deserialize(stream);
                    }
                    catch (SerializationException)
                    {
                        data = null;
                    }
                    finally
                    {
                        stream.Close();
                    }
                }
            }
            return data;
        }

19 View Source File : CloneUtil.cs
License : MIT License
Project Creator : active-logic

public static T DeepClone<T>(T obj){
        using (var ms = new MemoryStream()){
            var formatter = new BinaryFormatter();
            formatter.Serialize(ms, obj);
            ms.Position = 0;
            return (T)formatter.Deserialize(ms);
        }
    }

19 View Source File : PersistSequentialModel.cs
License : MIT License
Project Creator : adamtiger

public static SequentialModel DeserializeModel(string fileName)
        {
            SequentialModel model = null;
            if (File.Exists(fileName))
            {
                Stream stream = File.OpenRead(fileName);
                BinaryFormatter deserializer = new BinaryFormatter();
                model = (SequentialModel)deserializer.Deserialize(stream);
                stream.Close();
            }
            else
                throw new Exception("Trying to serialize a non-existing file.");

            return model;
        }

19 View Source File : Utils.cs
License : Apache License 2.0
Project Creator : aequabit

public static T DeepClone<T>(T obj)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, obj);
                stream.Position = 0L;
                return (T) formatter.Deserialize(stream);
            }
        }

19 View Source File : MetadataProvider.cs
License : MIT License
Project Creator : afaniuolo

public T DeepCopy<T>(T item)
		{
			BinaryFormatter formatter = new BinaryFormatter();
			MemoryStream stream = new MemoryStream();
			formatter.Serialize(stream, item);
			stream.Seek(0, SeekOrigin.Begin);
			T result = (T)formatter.Deserialize(stream);
			stream.Close();
			return result;
		}

19 View Source File : IOHelper.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public static T TryLoad<T>(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return default(T);
            }
            var t = default(T);
            using (var fs = new FileStream(fileName, FileMode.Open))
            {
                var ser = new BinaryFormatter();
                try
                {
                    t = (T)ser.Deserialize(fs);
                }
                catch
                {
                    return t;
                }
            }
            return t;
        }

19 View Source File : BytesAssetProcessor.cs
License : MIT License
Project Creator : aillieo

public BehaviorTree Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return null;
            }

            BehaviorTree behaviorTree = null;
            using (Stream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                behaviorTree = formatter.Deserialize(stream) as BehaviorTree;
                stream.Close();
            }
            return behaviorTree;
        }

19 View Source File : Serialization.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static object FromBinary(byte[] bs, bool verifyreplacedembly = false)
		{
			using (MemoryStream ms = new MemoryStream(bs))
			{
				BinaryFormatter bf = new BinaryFormatter();
				if (!verifyreplacedembly)
					bf.Binder = new LocalreplacedemblyBinder();
				return bf.Deserialize(ms);
			}
		}

19 View Source File : SerializeEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static object Deserialize(string path)
		{
			using (FileStream fs = File.OpenRead(path))
			{
				BinaryFormatter bf = new BinaryFormatter();
				bf.Binder = new LocalreplacedemblyBinder();
				return bf.Deserialize(fs);
			}
		}

19 View Source File : Serialization.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static object FromBinaryFile(string path, bool verifyreplacedembly = false)
		{
			using (FileStream fs = File.OpenRead(path))
			{
				BinaryFormatter bf = new BinaryFormatter();
				if (!verifyreplacedembly)
					bf.Binder = new LocalreplacedemblyBinder();
				return bf.Deserialize(fs);
			}
		}

19 View Source File : SerializeEngine.cs
License : GNU General Public License v3.0
Project Creator : aiportal

internal static object Deserialize(Stream stream)
		{
			BinaryFormatter bf = new BinaryFormatter();
			bf.Binder = new LocalreplacedemblyBinder();
			return bf.Deserialize(stream);
		}

19 View Source File : ObjectExtensions.cs
License : MIT License
Project Creator : albyho

public static object DeepClone(this object source)
        {
            if (source == null)
                return null;

            using (var memStream = new MemoryStream())
            {
                var binaryFormatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
                binaryFormatter.Serialize(memStream, source);
                memStream.Position = 0;
                return binaryFormatter.Deserialize(memStream);
            }
        }

19 View Source File : ObjectExtensions.cs
License : MIT License
Project Creator : albyho

public static T FromByteArray<T>(this byte[] byteArray) where T : clreplaced
        {
            if (byteArray == null)
            {
                return default(T);
            }
            var binaryFormatter = new BinaryFormatter();
            using (var memoryStream = new MemoryStream(byteArray))
            {
                return binaryFormatter.Deserialize(memoryStream) as T;
            }
        }

19 View Source File : SaveLoad.cs
License : GNU General Public License v3.0
Project Creator : AlexandreDoucet

public static void Load(out T serializableClreplaced, string fileName, string dataPath)
        {
            if (dataPath == null)
            {dataPath = Application.dataPath;}
            string destination = dataPath + "/"+ fileName;
            FileStream file;

            if (File.Exists(destination))
            {
                file = File.OpenRead(destination);
                BinaryFormatter bf = new BinaryFormatter();
                serializableClreplaced = (T)bf.Deserialize(file);
                file.Close();
            }
            else
            {
                serializableClreplaced = (T)Activator.CreateInstance(typeof(T), new object[] { });
            }
            Debug.Log("Load from to : " + destination);


        }

19 View Source File : TemplatesSettings.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

public static TemplatesSettings Load()
        {
            TemplatesSettings templates = new TemplatesSettings();

            if (File.Exists(pathFile))
            {
                using (var fileStream = new FileStream(pathFile, FileMode.Open))
                {
                    templates = (TemplatesSettings)new BinaryFormatter().Deserialize(fileStream);
                }
            }

            return templates;
        }

19 View Source File : Style.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

private static Style Load(string path, bool addToList)
		{
			try
			{
				using (Stream stream = new FileStream(path, FileMode.Open))
				{
					BinaryFormatter formatter = new BinaryFormatter();
					Style result = (Style) formatter.Deserialize(stream);

					if (addToList && result != null)
						AddToList(result, path);

					return result;
				}
			}
			catch
			{
				return null;
			}
		}

19 View Source File : ConnectionDialog.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

public static ConnectionsSettings Load()
        {
            ConnectionsSettings connectionsSettings = new ConnectionsSettings();

            if (File.Exists(pathFile))
            {
                using (var fileStream = new FileStream(pathFile, FileMode.Open))
                {
                    connectionsSettings = (ConnectionsSettings)new BinaryFormatter().Deserialize(fileStream);
                }
            }

            return connectionsSettings;
        }

19 View Source File : BuildingPrototype.cs
License : MIT License
Project Creator : AliakseiFutryn

protected object DeepClone()
		{
			object itemClone = MemberwiseClone();
			if (itemClone != null)
			{
				using (MemoryStream stream = new MemoryStream())
				{
					BinaryFormatter formatter = new BinaryFormatter();
					formatter.Serialize(stream, itemClone);
					stream.Position = 0;
					return formatter.Deserialize(stream);
				}

			}
			return null;
		}

19 View Source File : ObjectToByte.cs
License : MIT License
Project Creator : allartprotocol

public static object ByteArrayToObject(byte[] arrBytes)
        {
            using (var memStream = new MemoryStream())
            {
                var binForm = new BinaryFormatter();
                memStream.Write(arrBytes, 0, arrBytes.Length);
                memStream.Seek(0, SeekOrigin.Begin);
                object obj = binForm.Deserialize(memStream);
                return obj;
            }
        }

19 View Source File : DeepCopy.cs
License : MIT License
Project Creator : alonsoalon

public static T DeepCopyByBin<T>(T obj)
        {
            object retval;
            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                //序列化成流
                bf.Serialize(ms, obj);
                ms.Seek(0, SeekOrigin.Begin);
                //反序列化成对象
                retval = bf.Deserialize(ms);
                ms.Close();
            }
            return (T)retval;
        }

19 View Source File : DefaultBinaryFormatterSerializer.cs
License : MIT License
Project Creator : AlphaYu

public T Deserialize<T>(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                return (T)new BinaryFormatter().Deserialize(ms);
            }
        }

19 View Source File : DefaultBinaryFormatterSerializer.cs
License : MIT License
Project Creator : AlphaYu

public object Deserialize(byte[] bytes, Type type)
        {
            using (var ms = new MemoryStream(bytes))
            {
                return new BinaryFormatter().Deserialize(ms);
            }
        }

19 View Source File : DefaultBinaryFormatterSerializer.cs
License : MIT License
Project Creator : AlphaYu

public object DeserializeObject(ArraySegment<byte> value)
        {
            using (var ms = new MemoryStream(value.Array, value.Offset, value.Count))
            {
                return new BinaryFormatter().Deserialize(ms);
            }
        }

19 View Source File : MainForm.cs
License : Mozilla Public License 2.0
Project Creator : amrali-eg

private void LoadSettings()
        {
            string settingsFileName = GetSettingsFileName();
            if (!File.Exists(settingsFileName))
                return;
            using (FileStream settingsFile = new FileStream(settingsFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                object settingsInstance = formatter.Deserialize(settingsFile);
                _settings = (Settings)settingsInstance;
            }

            if (_settings.RecentDirectories?.Count > 0)
            {
                foreach (string recentDirectory in _settings.RecentDirectories)
                    lstBaseDirectory.Items.Add(recentDirectory);
                lstBaseDirectory.SelectedIndex = 0;
            }
            else
                lstBaseDirectory.Text = Environment.CurrentDirectory;
            chkIncludeSubdirectories.Checked = _settings.IncludeSubdirectories;
            txtFileMasks.Text = _settings.FileMasks;
            if (_settings.ValidCharsets?.Length > 0)
            {
                for (int i = 0; i < lstValidCharsets.Items.Count; i++)
                    if (Array.Exists(_settings.ValidCharsets,
                        charset => charset.Equals((string)lstValidCharsets.Items[i])))
                        lstValidCharsets.SereplacedemChecked(i, true);
            }

            _settings.WindowPosition?.ApplyTo(this);
        }

19 View Source File : Utils.cs
License : MIT License
Project Creator : Analogy-LogViewer

public static T DeSerializeBinaryFile<T>(string filename) where T : clreplaced, new()
        {
            var formatter = new BinaryFormatter();
            if (File.Exists(filename))
            {
                try
                {
                    using (Stream myReader = File.Open(filename, FileMode.Open, FileAccess.Read))
                    {
                        return (T)formatter.Deserialize(myReader);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("GeneralDataUtils: Error in DeSerializeBinaryFile", ex);
                }
            }

            throw new FileNotFoundException("GeneralDataUtils: File does not exist: " + filename, filename);
        }

19 View Source File : ObjectExtensions.cs
License : Apache License 2.0
Project Creator : AndcultureCode

public static T FromByteArray<T>(this byte[] byteArray) where T : clreplaced
        {
            if (byteArray == null)
            {
                return default(T);
            }

            var binaryFormatter = new BinaryFormatter();
            using (var memoryStream = new MemoryStream(byteArray))
            {
                return binaryFormatter.Deserialize(memoryStream) as T;
            }
        }

19 View Source File : SymetricCryptoService.cs
License : MIT License
Project Creator : ansel86castro

public object DecrypObject(byte[] data)
        {
            var decrypted = Decrypt(data);
            BinaryFormatter formatter = new BinaryFormatter();
            object value;
            using (MemoryStream memoryStream = new MemoryStream(decrypted))
            {
                value = formatter.Deserialize(memoryStream);
            }

            return value;
        }

19 View Source File : ResourceDataCreator.cs
License : GNU General Public License v3.0
Project Creator : anydream

bool GetSerializedTypeAndreplacedemblyName(byte[] value, out string replacedemblyName, out string typeName) {
			try {
				var formatter = new BinaryFormatter();
				formatter.Binder = new MyBinder();
				formatter.Deserialize(new MemoryStream(value));
			}
			catch (MyBinder.OkException ex) {
				replacedemblyName = ex.replacedemblyName;
				typeName = ex.TypeName;
				return true;
			}
			catch {
			}

			replacedemblyName = null;
			typeName = null;
			return false;
		}

19 View Source File : ParserBinary.cs
License : MIT License
Project Creator : aornelas

public override T DeserializeFromString<T>(string dataString) {
			MemoryStream memoryStream = new MemoryStream(new UTF8Encoding().GetBytes(dataString)); 
			BinaryFormatter serializer = new BinaryFormatter ();
			try {
				return (T)serializer.Deserialize (memoryStream);

			} catch (Exception e) {
				Debug.LogError ("Game data invalid from string: " + dataString + "; " + e.Message);
			}
			return default(T);
		}

19 View Source File : PropertiesDictionaryTest.cs
License : Apache License 2.0
Project Creator : apache

[Test]
		public void TestSerialization()
		{
			PropertiesDictionary pd = new PropertiesDictionary();

			for(int i = 0; i < 10; i++)
			{
				pd[i.ToString()] = i;
			}

			replacedert.AreEqual(10, pd.Count, "Dictionary should have 10 items");

			// Serialize the properties into a memory stream
			BinaryFormatter formatter = new BinaryFormatter();
			MemoryStream memory = new MemoryStream();
			formatter.Serialize(memory, pd);

			// Deserialize the stream into a new properties dictionary
			memory.Position = 0;
			PropertiesDictionary pd2 = (PropertiesDictionary)formatter.Deserialize(memory);

			replacedert.AreEqual(10, pd2.Count, "Deserialized Dictionary should have 10 items");

			foreach(string key in pd.GetKeys())
			{
				replacedert.AreEqual(pd[key], pd2[key], "Check Value Persisted for key [{0}]", key);
			}
		}

19 View Source File : SerializeUtility.cs
License : MIT License
Project Creator : ArcturusZhang

public static object DeserializeObject(byte[] bytes)
        {
            if (bytes == null) return null;
            BinaryFormatter binForm = new BinaryFormatter();
            using (var memStream = new MemoryStream())
            {
                memStream.Write(bytes, 0, bytes.Length);
                memStream.Seek(0, SeekOrigin.Begin);
                return (object)binForm.Deserialize(memStream);
            }
        }

19 View Source File : C3Addon.cs
License : GNU General Public License v3.0
Project Creator : armandoalonso

public object Clone()
        {
            object clone = null;
            using(var stream = new MemoryStream())
            {
                if (this.GetType().IsSerializable)
                {
                    var oldGuid = this.Id;
                    this.Id = Guid.NewGuid();
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(stream, this);
                    stream.Position = 0;
                    clone = formatter.Deserialize(stream);
                    this.Id = oldGuid;
                }
            }
            return clone;
        }

19 View Source File : NavMeshOcTree.cs
License : MIT License
Project Creator : AsehesL

public static NavMeshOcTree Load(string path)
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                NavMeshOcTree tree = bf.Deserialize(fs) as NavMeshOcTree;
                
                fs.Close();

                return tree;
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
                return null; 
            }
        }

19 View Source File : Utility.cs
License : MIT License
Project Creator : Ashesh3

public static T DeepClone<T>(this T obj)
        {
            using (var ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, obj);
                ms.Position = 0;

                return (T)formatter.Deserialize(ms);
            }
        }

19 View Source File : AddInDomainSetup.cs
License : MIT License
Project Creator : askguanyu

private T CloneDeep<T>(T source)
        {
            if (source == null)
            {
                return default(T);
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                binaryFormatter.Serialize(memoryStream, source);
                memoryStream.Position = 0;
                return (T)binaryFormatter.Deserialize(memoryStream);
            }
        }

19 View Source File : AddInDomainSetup.cs
License : MIT License
Project Creator : askguanyu

internal static AddInDomainSetup ReadSetupFile(string filename)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                return (AddInDomainSetup)formatter.Deserialize(fileStream);
            }
        }

19 View Source File : NetworkProtocol.cs
License : Apache License 2.0
Project Creator : aws-samples

public static SimpleMessage[] Receive(TcpClient client)
    {
        NetworkStream stream = client.GetStream();
        var messages = new List<SimpleMessage>();
        while (stream.DataAvailable)
        {
            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                SimpleMessage message = formatter.Deserialize(stream) as SimpleMessage;
                messages.Add(message);
            }
            catch(Exception e)
            {
                System.Console.WriteLine("Error receiving a message: " + e.Message);
                System.Console.WriteLine("Aborting the rest of the messages");
                break;
            }
        }

        return messages.ToArray();
    }

19 View Source File : AyFuncMultiplyScreenRecord.cs
License : MIT License
Project Creator : ay2015

public Dictionary<string, SystemWindowInScreenStatus> LoadSystemWindowInScreenStatus()
        {
            Dictionary<string, SystemWindowInScreenStatus> ss = null;

            if (File.Exists(data))
            {
                using (FileStream fs = new FileStream(data, FileMode.Open))
                {
                    //二进制格式化
                    BinaryFormatter bf = new BinaryFormatter();
                    //反序列化
                    ss = (Dictionary<string, SystemWindowInScreenStatus>)bf.Deserialize(fs);
                }
            }
            return ss;
        }

19 View Source File : MSBinaryFormatter.cs
License : MIT License
Project Creator : azist

public object Deserialize(System.IO.Stream stream)
      {
          return m_Formatter.Deserialize(stream);
      }

19 View Source File : SerializerForm2.cs
License : MIT License
Project Creator : azist

private void button5_Click(object sender, EventArgs e)
        {
          var ms = new MemoryStream();

            var bf = new BinaryFormatter();

             bf.Serialize(ms, data);

            var w = Stopwatch.StartNew();
            for(var i=0; i<CNT; i++)
            {
             ms.Position = 0;
             bf.Deserialize(ms);
            }

            w.Stop();
            Text = string.Format("Bin Formatter deserialized {0:n2} in {1:n2} ms, {2:n2}/sec {3}bytes",CNT, w.ElapsedMilliseconds, (CNT/(double)w.ElapsedMilliseconds)*1000, ms.Length);
        }

19 View Source File : SerializerForm.cs
License : MIT License
Project Creator : azist

private void button2_Click(object sender, EventArgs e)
        {
             var tr = new TypeRegistry(
                                  TypeRegistry.CommonCollectionTypes,
                                  TypeRegistry.BoxedCommonTypes,
                                  TypeRegistry.BoxedCommonNullableTypes);

             tr.Add(typeof(Person2));
             tr.Add(typeof(System.Drawing.Point));
             tr.Add(typeof(TimeSpan));
             tr.Add(typeof(Kozel));

              var p1 = make();



              using (var ms = new FileStream(@"c:\Azos\PERSON2.slim", FileMode.Create) )//new MemoryStream())
              {
                var s = new SlimSerializer(tr);

                s.Serialize(ms, p1);

                var clk = Stopwatch.StartNew();

                for(var i=1; i<4000; i++)
                {
                  ms.Seek(0, SeekOrigin.Begin);
                  var p2 = s.Deserialize(ms);
                }
                Text = clk.ElapsedMilliseconds.ToString();

                //Text = p2.Name;
              }

              //BINARY formatterr

              using (var ms = new FileStream(@"c:\Azos\PERSON2.bin", FileMode.Create) ) //new MemoryStream())
              {
                var s = new BinaryFormatter();

                s.Serialize(ms, p1);

                var clk = Stopwatch.StartNew();

                for(var i=1; i<4000; i++)
                {
                  ms.Seek(0, SeekOrigin.Begin);
                  var p2 = s.Deserialize(ms);
                }
                Text += "        Binary formatter: " + clk.ElapsedMilliseconds.ToString();
              }
        }

See More Examples