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 Source : CommandLineSwitchException_Tests.cs
with MIT License
from enricosada

[Test]
        public void SerializeDeserialize2()
        {
            try
            {
                CommandLineSwitchException.Throw("InvalidNodeNumberValueIsNegative", null);
            }
            catch (CommandLineSwitchException e)
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(memStream, e);
                    memStream.Position = 0;

                    CommandLineSwitchException e2 = (CommandLineSwitchException)formatter.Deserialize(memStream);

                    replacedert.AreEqual(e.Message, e2.Message);
                }
            }
        }

19 Source : InitializationException_Tests.cs
with MIT License
from enricosada

[Test]
        public void SerializeDeserialize()
        {
            try 
            {
                InitializationException.Throw("message", "invalidSwitch");
            }
            catch(InitializationException e)
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(memStream, e);
                    memStream.Position = 0;

                    InitializationException e2 = (InitializationException)formatter.Deserialize(memStream);

                    replacedert.AreEqual(e.Message, e2.Message);
                }
            }
        }

19 Source : InitializationException_Tests.cs
with MIT License
from enricosada

[Test]
        public void SerializeDeserialize2()
        {
            try
            {
                InitializationException.Throw("message", null);
            }
            catch (InitializationException e)
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(memStream, e);
                    memStream.Position = 0;

                    InitializationException e2 = (InitializationException)formatter.Deserialize(memStream);

                    replacedert.AreEqual(e.Message, e2.Message);
                }
            }
        }

19 Source : StateFileBase.cs
with MIT License
from enricosada

static internal StateFileBase DeserializeCache(string stateFile, TaskLoggingHelper log, Type requiredReturnType)
        {
            StateFileBase retVal = null;

            // First, we read the cache from disk if one exists, or if one does not exist
            // then we create one.  
            try
            {
                if (!string.IsNullOrEmpty(stateFile) && File.Exists(stateFile))
                {
                    using (FileStream s = new FileStream(stateFile, FileMode.Open))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        object deserializedObject = formatter.Deserialize(s);
                        retVal = deserializedObject as StateFileBase;

                        // If the deserialized object is null then there would be no cast error but retVal would still be null
                        // only log the message if there would have been a cast error
                        if (retVal == null && deserializedObject != null)
                        {
                            // When upgrading to Visual Studio 2008 and running the build for the first time the resource cache files are replaced which causes a cast error due
                            // to a new version number on the tasks clreplaced. "Unable to cast object of type 'Microsoft.Build.Tasks.SystemState' to type 'Microsoft.Build.Tasks.StateFileBase".
                            // If there is an invalid cast, a message rather than a warning should be emitted.
                            log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
                        }

                        if ((retVal != null) && (!requiredReturnType.IsInstanceOfType(retVal)))
                        {
                            log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", stateFile,
                                log.FormatResourceString("General.IncompatibleStateFileType"));
                            retVal = null;
                        }

                        // If we get back a valid object and internals were changed, things are likely to be null. Check the version before we use it.
                        if (retVal != null && retVal._serializedVersion != CurrentSerializationVersion)
                        {
                            log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
                            retVal = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (ExceptionHandling.IsCriticalException(e))
                {
                    throw;
                }

                // The deserialization process seems like it can throw just about 
                // any exception imaginable.  Catch them all here.
                // Not being able to deserialize the cache is not an error, but we let the user know anyway.
                // Don't want to hold up processing just because we couldn't read the file.
                log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", stateFile, e.Message);
            }

            return retVal;
        }

19 Source : MenuItem.cs
with GNU General Public License v2.0
from ensoulsharp-io

internal static T3 Deserialize<T3>(byte[] arrBytes)
        {
            var memStream = new MemoryStream();
            var binForm = new BinaryFormatter { Binder = new AllowAllreplacedemblyVersionsDeserializationBinder() };
            memStream.Write(arrBytes, 0, arrBytes.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            return (T3)binForm.Deserialize(memStream);
        }

19 Source : BinaryItemFormatter.cs
with Apache License 2.0
from enyim

private object? DoDeserialize(ReadOnlyMemory<byte> data, uint flags)
		{
			if (flags == RawDataFlag
				// check if unknown flag
				|| ((flags & (FlagPrefix + 0xff)) != flags))
				return data.ToArray();

			var code = (TypeCode)(flags & 0xff);
			var span = data.Span;

#pragma warning disable IDE0049 // readability

			switch (code)
			{
				case TypeCode.Object:
					if (!MemoryMarshal.TryGetArray(data, out var segment))
						throw new SerializationException("Cannot deserialize object, MemoryMarshal was not able to get the byte[] of the buffer."); // TODO dump the first 16-32 bytes into the exception

					using (var ms = new MemoryStream(segment.Array, segment.Offset, segment.Count, false))
						return new BinaryFormatter().Deserialize(ms);

				case TypeCode.DBNull: return null;

				// incrementing a non-existing key then getting it
				// returns as a string, but the flag will be 0
				// so treat all 0 flagged items as string
				// this may help inter-client data management as well
				case TypeCode.Empty:
				case TypeCode.String: return Utf8NoBom.GetString(span);

				case TypeCode.SByte: return (SByte)span[0];
				case TypeCode.Byte: return span[0];
				case TypeCode.Boolean: return span[0] != FALSE;

				case TypeCode.Char: return (char)BinaryPrimitives.ReadUInt16LittleEndian(span);

				case TypeCode.Int16: return BinaryPrimitives.ReadInt16LittleEndian(span);
				case TypeCode.Int32: return BinaryPrimitives.ReadInt32LittleEndian(span);
				case TypeCode.Int64: return BinaryPrimitives.ReadInt64LittleEndian(span);

				case TypeCode.UInt16: return BinaryPrimitives.ReadUInt16LittleEndian(span);
				case TypeCode.UInt32: return BinaryPrimitives.ReadUInt32LittleEndian(span);
				case TypeCode.UInt64: return BinaryPrimitives.ReadUInt64LittleEndian(span);

				case TypeCode.DateTime: return DateTime.FromBinary(BinaryPrimitives.ReadInt64LittleEndian(span));

				case TypeCode.Single: return BitConverter.ToSingle(span);
				case TypeCode.Double: return BitConverter.ToDouble(span);
				case TypeCode.Decimal:

					var bits = new int[4];
					bits[0] = BinaryPrimitives.ReadInt32LittleEndian(span);
					bits[1] = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(sizeof(Int32)));
					bits[2] = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(sizeof(Int32) + sizeof(Int32)));
					bits[3] = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(sizeof(Int32) + sizeof(Int32) + sizeof(Int32)));

					return new Decimal(bits);
			}
#pragma warning restore IDE0049

			return data.ToArray();
		}

19 Source : ObjectSerializer.cs
with MIT License
from EomTaeWook

public static List<T> DeserializeObject<T>(byte[] data)
        {
            var list = new List<T>();
            using (var ms = new MemoryStream(data))
            {
                var bf = new BinaryFormatter();
                var properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                            .Where(r => r.CustomAttributes.Any(a => a.AttributeType == typeof(OrderAttribute)))
                                            .OrderBy(o => ((OrderAttribute)o.GetCustomAttribute(typeof(OrderAttribute))).Order);

                if (properties.Count() == 0)
                    properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                                .Where(r => r.CanRead && r.CanWrite)
                                                .OrderBy(o => o.Name);

                while (ms.Position < ms.Length)
                {
                    var startTag = bf.Deserialize(ms);
                    if (!startTag.Equals("\uFF1C"))
                    {
                        throw new FormatException(DoreplacedentHelper.Get(Utils.Doreplacedent.Message.FailedFileBroken));
                    }
                    var @object = (T)Activator.CreateInstance(typeof(T));
                    bool isComplete = true;
                    foreach (var prop in properties)
                    {
                        var val = bf.Deserialize(ms);
                        if (val.Equals("\uFF1E"))
                        {
                            isComplete = false;
                            break;
                        }
                        prop.SetValue(@object, val);
                    }
                    if (isComplete)
                    {
                        var endTag = bf.Deserialize(ms);
                        if (!endTag.Equals("\uFF1E"))
                            throw new FormatException(DoreplacedentHelper.Get(Utils.Doreplacedent.Message.FailedFileBroken));
                    }
                    list.Add(@object);
                }
            }
            return list;
        }

19 Source : DomainObject.cs
with MIT License
from evelasco85

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 Source : SaveTour.cs
with GNU General Public License v3.0
from exewin

public static void Load (string filePath) 
	{
		SaveTour data = new SaveTour ();
		Stream stream = File.Open(filePath, FileMode.Open);
		BinaryFormatter bformatter = new BinaryFormatter();
		bformatter.Binder = new VersionDeserializationBindere(); 
		data = (SaveTour)bformatter.Deserialize(stream);
		stream.Close();

	// Now use "data" to access your Values
	}

19 Source : SaveData.cs
with GNU General Public License v3.0
from exewin

public static void Load (string filePath) 
	{
		SaveData data = new SaveData ();
		Stream stream = File.Open(filePath, FileMode.Open);
		BinaryFormatter bformatter = new BinaryFormatter();
		bformatter.Binder = new VersionDeserializationBinder(); 
		data = (SaveData)bformatter.Deserialize(stream);
		stream.Close();

	// Now use "data" to access your Values
	}

19 Source : CustomHeaders.cs
with MIT License
from Expecho

internal static CustomHeaders Deserialize(byte[] data)
        {
            using (var stream = new MemoryStream(data))
            {
                var bf = new BinaryFormatter();
                return (CustomHeaders)bf.Deserialize(stream);
            }
        }

19 Source : ObjectExtensions.cs
with MIT License
from eznew-net

static T DeepCloneByBinary<T>(T sourceObject)
        {
            if (sourceObject == null)
            {
                return default;
            }
            using (MemoryStream memoryStream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(memoryStream, sourceObject);
                memoryStream.Position = 0;
                var data = (T)formatter.Deserialize(memoryStream);
                return data;
            }
        }

19 Source : WhatUsesThis.cs
with MIT License
from Facepunch

static Dictionary<string, List<string>> Load()
		{
			try
			{
				var sw = System.Diagnostics.Stopwatch.StartNew();
				using ( var stream = new System.IO.FileStream( CacheFilename, System.IO.FileMode.Open ) )
				{
					BinaryFormatter bin = new BinaryFormatter();
					_dict = (Dictionary<string, List<string>>)bin.Deserialize( stream );
				}
				//Debug.Log( $"Loading took {sw.Elapsed.TotalSeconds}s" );
			}
			catch ( System.Exception )
			{
				_dict = null;
			}

			return _dict;
		}

19 Source : BinaryCompressSerializer.cs
with GNU General Public License v3.0
from faib920

[SuppressMessage("Microsoft.Usage", "CA2202")]
        public override T Deserialize<T>(byte[] bytes)
        {
            byte[] data;

            if (Token != null && Token.Data != null && Token.Data.Length > 0)
            {
                data = new byte[bytes.Length - Token.Data.Length];
                Array.Copy(bytes, Token.Data.Length, data, 0, data.Length);

                if (Token.Data.Where((t, i) => t != bytes[i]).Any())
                {
                    throw new SerializationException(SR.GetString(SRKind.SerializationTokenInvalid));
                }
            }
            else
            {
                data = bytes;
            }

            T obj;
            try
            {
                using (var stream = new MemoryStream(data))
                using (var zipStream = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    var bin = new BinaryFormatter
                        {
                            Binder = new IgnoreSerializationBinder()
                        };
                    obj = (T)bin.Deserialize(zipStream);
                }
            }
            catch (Exception ex)
            {
                throw new SerializationException(SR.GetString(SRKind.DeserializationError), ex);
            }

            return obj;
        }

19 Source : BinaryCryptoSerializer.cs
with GNU General Public License v3.0
from faib920

public override T Deserialize<T>(byte[] bytes)
        {
            byte[] data;

            if (Token != null && Token.Data != null && Token.Data.Length > 0)
            {
                data = new byte[bytes.Length - Token.Data.Length];
                Array.Copy(bytes, Token.Data.Length, data, 0, data.Length);

                if (Token.Data.Where((t, i) => t != bytes[i]).Any())
                {
                    throw new SerializationException(SR.GetString(SRKind.SerializationTokenInvalid));
                }
            }
            else
            {
                data = bytes;
            }

            T obj;
            try
            {
                using (var stream = new MemoryStream(cryptoProvider.Decrypt(data)))
                {
                    var bin = new BinaryFormatter
                        {
                            Binder = new IgnoreSerializationBinder()
                        };
                    obj = (T)bin.Deserialize(stream);
                }
            }
            catch (Exception ex)
            {
                throw new SerializationException(SR.GetString(SRKind.DeserializationError), ex);
            }

            return obj;
        }

19 Source : StackExchangeRedisExtensions.cs
with MIT License
from fanliang11

static T Deserialize<T>(byte[] stream)
        {
            if (stream == null)
            {
                return default(T);
            }

            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (MemoryStream memoryStream = new MemoryStream(stream))
            {
                T result = (T)binaryFormatter.Deserialize(memoryStream);
                return result;
            }
        }

19 Source : PathfinderData.cs
with Apache License 2.0
from FieldWarning

private bool ReadGraph(string file)
        {
            if (!File.Exists(file))
                return false;

            try
            {
                Stream stream = File.Open(file, FileMode.Open);
                BinaryFormatter formatter = new BinaryFormatter();

                _graphFastMove = (List<PathNode>)formatter.Deserialize(stream);
                stream.Close();

                //_openSet = new FastPriorityQueue<PathNode>(_graphFastMove.Count + 1);

                if (SanityCheckGraph())
                {
                    return true;
                }
                //else 
                //{
                //    _graphFastMove = null;
                //    _openSet = null;
                //    return false;
                //}
            }
            catch (Exception exception)
            {
                Debug.Log("Error reading graph file: " + exception.Message);
                return false;
            }

            return true;
        }

19 Source : StringCorruptionTest.cs
with BSD 3-Clause "New" or "Revised" License
from FireFox2000000

void ReadClipboardFromFile()
    {
        FileStream fs = null;
        clipboard = null;

        try
        {
            // Read clipboard data from a file instead of the actual clipboard because the actual clipboard doesn't work for whatever reason
            fs = new FileStream(ClipboardObjectController.CLIPBOARD_FILE_LOCATION, FileMode.Open);
            BinaryFormatter formatter = new BinaryFormatter();

            clipboard = (Clipboard)formatter.Deserialize(fs);
        }
        catch (System.Exception e)
        {
            Logger.LogException(e, "Failed to read from clipboard file");
            clipboard = null;
        }
        finally
        {
            if (fs != null)
                fs.Close();
            else
                Debug.LogError("Filestream when reading clipboard data failed to initialise");
        }

        if (clipboard != null)
        {
            foreach (SongObject clipboardSongObject in clipboard.data)
            {
                PlaceSongObject.AddObjectToCurrentEditor(clipboardSongObject.Clone(), editor, false);
            }
        }
    }

19 Source : ClipboardObjectController.cs
with BSD 3-Clause "New" or "Revised" License
from FireFox2000000

public void Paste(uint chartLocationToPaste)
    {
        //if (System.Windows.Forms.Clipboard.GetDataObject().GetFormats().Length > 0 && 
        //    !(
        //        System.Windows.Forms.Clipboard.ContainsText(TextDataFormat.UnicodeText) && 
        //        System.Windows.Forms.Clipboard.ContainsText(TextDataFormat.Text) && 
        //        System.Windows.Forms.Clipboard.GetText() == "")
        //    )     // Something else is pasted on the clipboard instead of Moonscraper stuff.
        //    return;

        FileStream fs = null;
        clipboard = null;
        try
        {
            // Read clipboard data from a file instead of the actual clipboard because the actual clipboard doesn't work for whatever reason
            fs = new FileStream(CLIPBOARD_FILE_LOCATION, FileMode.Open);
            BinaryFormatter formatter = new BinaryFormatter();

            clipboard = (Clipboard)formatter.Deserialize(fs);
        }
        catch (System.Exception e)
        {
            Logger.LogException(e, "Failed to read from clipboard file");
            clipboard = null;
        }
        finally
        {
            if (fs != null)
                fs.Close();
            else
                Debug.LogError("Filestream when reading clipboard data failed to initialise");
        }

        if (editor.currentState == ChartEditor.State.Editor && clipboard != null && clipboard.data.Length > 0)
        {
            List<SongEditCommand> commands = new List<SongEditCommand>();

            Rect collisionRect = clipboard.GetCollisionRect(chartLocationToPaste, editor.currentSong);
            if (clipboard.areaChartPosMin > clipboard.areaChartPosMax)
            {
                Debug.LogError("Clipboard minimum (" + clipboard.areaChartPosMin + ") is greater than clipboard the max (" + clipboard.areaChartPosMax + ")");
            }
            uint colliderChartDistance = TickFunctions.TickScaling(clipboard.areaChartPosMax - clipboard.areaChartPosMin, clipboard.resolution, editor.currentSong.resolution);

            editor.globals.ToggleSongViewMode(!clipboard.data[0].GetType().IsSubclreplacedOf(typeof(ChartObject)));

            {
                List<SongObject> newObjectsToDelete = new List<SongObject>();

                // Overwrite any objects in the clipboard space
                if (clipboard.data[0].GetType().IsSubclreplacedOf(typeof(ChartObject)))
                {
                    foreach (ChartObject chartObject in editor.currentChart.chartObjects)
                    {
                        if (chartObject.tick >= chartLocationToPaste && chartObject.tick <= (chartLocationToPaste + colliderChartDistance) && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(chartObject), collisionRect))
                        {
                            newObjectsToDelete.Add(chartObject);
                        }
                    }
                }
                else
                {
                    // Overwrite synctrack, leave sections alone
                    foreach (SyncTrack syncObject in editor.currentSong.syncTrack)
                    {
                        if (syncObject.tick >= chartLocationToPaste && syncObject.tick <= (chartLocationToPaste + colliderChartDistance) && PrefabGlobals.HorizontalCollisionCheck(PrefabGlobals.GetCollisionRect(syncObject), collisionRect))
                        {
                            newObjectsToDelete.Add(syncObject);
                        }
                    }
                }

                if (newObjectsToDelete.Count > 0)
                {
                    commands.Add(new SongEditDelete(newObjectsToDelete));
                }
            }

            {
                uint maxLength = editor.currentSong.TimeToTick(editor.currentSongLength, editor.currentSong.resolution);

                List<SongObject> newObjectsToAddIn = new List<SongObject>();

                // Paste the new objects in
                foreach (SongObject clipboardSongObject in clipboard.data)
                {
                    SongObject objectToAdd = clipboardSongObject.Clone();

                    objectToAdd.tick = chartLocationToPaste +
                        TickFunctions.TickScaling(clipboardSongObject.tick, clipboard.resolution, editor.currentSong.resolution) -
                        TickFunctions.TickScaling(clipboard.areaChartPosMin, clipboard.resolution, editor.currentSong.resolution);

                    if (objectToAdd.tick >= maxLength)
                        break;

                    if (objectToAdd.GetType() == typeof(Note))
                    {
                        Note note = (Note)objectToAdd;

                        if (clipboard.instrument == Song.Instrument.GHLiveGuitar || clipboard.instrument == Song.Instrument.GHLiveBreplaced)
                        {
                            // Pasting from a ghl track
                            if (!Globals.ghLiveMode)
                            {
                                if (note.ghliveGuitarFret == Note.GHLiveGuitarFret.Open)
                                    note.guitarFret = Note.GuitarFret.Open;
                                else if (note.ghliveGuitarFret == Note.GHLiveGuitarFret.White3)
                                    continue;
                            }
                        }
                        else if (Globals.ghLiveMode)
                        {
                            // Pasting onto a ghl track
                            if (note.guitarFret == Note.GuitarFret.Open)
                                note.ghliveGuitarFret = Note.GHLiveGuitarFret.Open;
                        }

                        note.length = TickFunctions.TickScaling(note.length, clipboard.resolution, editor.currentSong.resolution);
                    }
                    else if (objectToAdd.GetType() == typeof(Starpower))
                    {
                        Starpower sp = (Starpower)objectToAdd;
                        if (editor.currentInstrument != Song.Instrument.Drums)
                        {
                            sp.flags &= ~Starpower.Flags.ProDrums_Activation;
                        }
                        sp.length = TickFunctions.TickScaling(sp.length, clipboard.resolution, editor.currentSong.resolution);
                    }

                    newObjectsToAddIn.Add(objectToAdd);
                }

                if (newObjectsToAddIn.Count > 0)
                {
                    commands.Add(new SongEditAdd(newObjectsToAddIn));
                }
            }

            if (commands.Count > 0)
            {
                BatchedSongEditCommand batchedCommands = new BatchedSongEditCommand(commands);
                editor.commandStack.Push(batchedCommands);
            }
        }
        // 0 objects in clipboard, don't bother pasting
    }

19 Source : Settings.cs
with GNU General Public License v3.0
from flamewave000

public static async Task Load() => await Task.Run(() =>
		{
			if (!File.Exists("props.bin"))
			{
				data = new Data
				{
					overlayClickable = true,
					savePositions = false,
					overlayRect = new Rect { Size = new Size(Constants.OverlayStartWidth, Constants.OverlayStartHeight), Point = Point.Empty },
					containerRect = new Rect { Size = new Size(Constants.StartWidth, Constants.StartHeight), Point = Point.Empty },
					transparencyKey = Constants.DefaultTransparencyKey,
					frameRate = 10
				};
				return;
			}
			using (FileStream stream = new FileStream("props.bin", FileMode.OpenOrCreate))
			{
				var value = new BinaryFormatter().Deserialize(stream);
				data = (Data)value;
				// Migrate data for new property
				if (data.frameRate == 0)
					data.frameRate = 10;
			}
		});

19 Source : ContainerMessage.cs
with Apache License 2.0
from florinleon

public static object Deserialize(string s)
        {
            byte[] bytes = Convert.FromBase64String(s);
            var stream = new MemoryStream(bytes);
            var bf = new BinaryFormatter();
            return bf.Deserialize(stream);
        }

19 Source : BinaryStorage.cs
with MIT License
from Flow-Launcher

private T Deserialize(FileStream stream, T defaultData)
        {
            //http://stackoverflow.com/questions/2120055/binaryformatter-deserialize-gives-serializationexception
            AppDomain.CurrentDomain.replacedemblyResolve += CurrentDomain_replacedemblyResolve;
            BinaryFormatter binaryFormatter = new BinaryFormatter
            {
                replacedemblyFormat = FormatterreplacedemblyStyle.Simple
            };

            try
            {
                var t = ((T)binaryFormatter.Deserialize(stream)).NonNull();
                return t;
            }
            catch (System.Exception e)
            {
                Log.Exception($"|BinaryStorage.Deserialize|Deserialize error for file <{FilePath}>", e);
                return defaultData;
            }
            finally
            {
                AppDomain.CurrentDomain.replacedemblyResolve -= CurrentDomain_replacedemblyResolve;
            }
        }

19 Source : BinaryBlueprint.cs
with GNU General Public License v3.0
from FNGgames

public Blueprint Deserialize() {
            Blueprint blueprint;
            if(blueprintData == null || blueprintData.Length == 0) {
                blueprint = new Blueprint(string.Empty, "New Blueprint", null);
            } else {
                using (var stream = new MemoryStream(blueprintData)) {
                    blueprint = (Blueprint)_serializer.Deserialize(stream);
                }
            }

            name = blueprint.name;
            return blueprint;
        }

19 Source : Functions.cs
with GNU General Public License v3.0
from Foxlider

public static T CloneObjectSerializable < T > (this T obj) where T: clreplaced {  
            MemoryStream    ms = new MemoryStream();  
            BinaryFormatter bf = new BinaryFormatter();  
            bf.Serialize(ms, obj);  
            ms.Position = 0;  
            object result = bf.Deserialize(ms);  
            ms.Close();  
            return (T) result;  
        }

19 Source : TerrainHistoryUtility.cs
with MIT License
from FritzsHero

public static List<TerrainHistoryMaker> LoadTerrainHistory(Road _road)
        {
            string path = CheckNonreplacedetDirTH() + GetRoadTHFilename(ref _road);
            if (string.IsNullOrEmpty(path) || path.Length < 2)
            {
                return null;
            }
            if (!File.Exists(path))
            {
                return null;
            }
            List<TerrainHistoryMaker> result;
            Stream stream = File.Open(path, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.Binder = new VersionDeserializationBinder();

            result = (List<TerrainHistoryMaker>)bFormatter.Deserialize(stream);

            stream.Close();
            return result;
        }

19 Source : EasyCacheRedisManager.cs
with MIT License
from furkandeveloper

public virtual T Get<T>(string key)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (var memoryStream = new MemoryStream())
            {
                var bytes = distributedCache.Get(key);
                if (bytes is null) return default(T);

                memoryStream.Write(bytes, 0, bytes.Length);

                memoryStream.Seek(0, SeekOrigin.Begin);

                return (T)binaryFormatter.Deserialize(memoryStream);
            }
        }

19 Source : EasyCacheRedisManager.cs
with MIT License
from furkandeveloper

public virtual async Task<T> GetAsync<T>(string key)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (var memoryStream = new MemoryStream())
            {
                var bytes = await distributedCache.GetAsync(key);
                if (bytes is null) return default(T);

                memoryStream.Write(bytes, 0, bytes.Length);

                memoryStream.Seek(0, SeekOrigin.Begin);

                return (T)binaryFormatter.Deserialize(memoryStream);
            }
        }

19 Source : UIScoreList.cs
with MIT License
from FuzzySlipper

public static T[] GetDataArray<T>(string key) where T : clreplaced {
            if (PlayerPrefs.HasKey(key) == false) {
                return null;
            }
            string str = PlayerPrefs.GetString(key);
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream(Convert.FromBase64String(str));
            return bf.Deserialize(ms) as T[];
        }

19 Source : SettingsProvider.cs
with MIT License
from G-Stas

private static void LoadSettings()
        {
            if(File.Exists(SettingsFullPath))
            {
                try
                {
                    using(var fileStream = new FileStream(SettingsFullPath, FileMode.Open))
                    {
                        fileStream.Position = 0;
                        Settings = (AppSettings) new BinaryFormatter().Deserialize(fileStream);
                    }
                    return;
                }
                catch(Exception e) { Logger.Error("Failed to load settings file", e); }
            }
        
            //write default values to file on first launch or if config file doesn't exist or deserialization failed
            Settings = new AppSettings { CurrentAppTheme = AppTheme.System, AppLanguage = TranslationSource.GetSystemLanguage() };
            SaveSettings().GetAwaiter().GetResult();
        }

19 Source : SaveLoad.cs
with MIT License
from GabrielePicco

public static List<GameIstance> GetGameIstances()
    {
        if (File.Exists(Path.Combine(UnityEngine.Application.persistentDataPath, "savedGames.gd")))
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file = File.Open(Path.Combine(UnityEngine.Application.persistentDataPath, "savedGames.gd"), FileMode.Open);
            SaveLoad.savedGames = (List<GameIstance>)bf.Deserialize(file);
            file.Close();
        }
        return SaveLoad.savedGames;
    }

19 Source : SaveData.cs
with MIT License
from GameGrind

public static T Load<T>(string key)
    {
        // Set the path to the persistent data path (works on most devices by default)
        string path = Application.persistentDataPath + "/saves/";
        // Grab an instance of the BinaryFormatter that will handle serializing our data
        BinaryFormatter formatter = new BinaryFormatter();
        // Open up a filestream, combining the path and object key
        FileStream fileStream = new FileStream(path + key + ".txt", FileMode.Open);
        // Initialize a variable with the default value of whatever type we're using
        T returnValue = default(T);
        /* 
         * Try/Catch/Finally block that will attempt to deserialize the data
         * If we fail to successfully deserialize the data, we'll just return the default value for Type
         */
        try
        {
            returnValue = (T)formatter.Deserialize(fileStream);
        }
        catch (SerializationException exception)
        {
            Debug.Log("Load failed. Error: " + exception.Message);
        }
        finally
        {
            fileStream.Close();
        }

        return returnValue;
    }

19 Source : SoftBasic.cs
with GNU Lesser General Public License v3.0
from gentlman2006

public static object DeepClone(object oringinal)
        {
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter()
                {
                    Context = new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.Clone)
                };
                formatter.Serialize(stream, oringinal);
                stream.Position = 0;
                return formatter.Deserialize(stream);
            }
        }

19 Source : FileStorageProvider.cs
with MIT License
from GetScatter

public void Load()
        {
            if (!File.Exists(FilePath))
            {
                Data = new AppData();
                return;
            }

            var bf = new BinaryFormatter();
            var fs = File.Open(FilePath, FileMode.Open);
            Data = (AppData)bf.Deserialize(fs);

            fs.Close();
        }

19 Source : PacketSerializer.cs
with MIT License
from gigajew

public IPacket Deserialize(Stream stream)
        {
            formatter.Binder = new BindChanger();
            return (IPacket)formatter.Deserialize(stream);
        }

19 Source : BadRequestExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf400()
        {
            var sut = new BadRequestException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as BadRequestException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete 
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status400BadRequest, sut.StatusCode);
        }

19 Source : GoneExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf410()
        {
            var sut = new GoneException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as GoneException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete 
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status410Gone, sut.StatusCode);
        }

19 Source : PreconditionFailedExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf412()
        {
            var sut = new PreconditionFailedException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as PreconditionFailedException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status412PreconditionFailed, sut.StatusCode);
        }

19 Source : ForbiddenExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf403()
        {
            var sut = new ForbiddenException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as ForbiddenException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status403Forbidden, sut.StatusCode);
        }

19 Source : MethodNotAllowedExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf405()
        {
            var sut = new MethodNotAllowedException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as MethodNotAllowedException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status405MethodNotAllowed, sut.StatusCode);
        }

19 Source : NotAcceptableExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf405()
        {
            var sut = new NotAcceptableException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as NotAcceptableException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status406NotAcceptable, sut.StatusCode);
        }

19 Source : NotFoundExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf404()
        {
            var sut = new NotFoundException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as NotFoundException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status404NotFound, sut.StatusCode);
        }

19 Source : PayloadTooLargeExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf413()
        {
            var sut = new PayloadTooLargeException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as PayloadTooLargeException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status413PayloadTooLarge, sut.StatusCode);
        }

19 Source : TooManyRequestsExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf429()
        {
            var sut = new TooManyRequestsException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as TooManyRequestsException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status429TooManyRequests, sut.StatusCode);
        }

19 Source : UnauthorizedExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf401()
        {
            var sut = new UnauthorizedException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as UnauthorizedException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status401Unauthorized, sut.StatusCode);
        }

19 Source : ExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void DataAdapterException_ShouldBeSerializable()
        {
            var ex = new DataAdapterException(Generate.RandomString(10));

            TestOutput.WriteLine(ex.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, ex);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as DataAdapterException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(ex.Message, desEx.Message);
                replacedert.Equal(ex.ToString(), desEx.ToString());
            }
        }

19 Source : ExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void UniqueIndexViolationException_ShouldBeSerializable()
        {
            var ex = new UniqueIndexViolationException(Generate.RandomString(10));

            TestOutput.WriteLine(ex.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, ex);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as UniqueIndexViolationException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(ex.Message, desEx.Message);
                replacedert.Equal(ex.ToString(), desEx.ToString());
            }
        }

19 Source : ExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void UserAgentException_ShouldBeSerializable()
        {
            var ex = new UserAgentException(400, "Bad Request.");

            TestOutput.WriteLine(ex.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, ex);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as UserAgentException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(ex.StatusCode, desEx.StatusCode);
                replacedert.Equal(ex.Message, desEx.Message);
                replacedert.Equal(ex.ToString(), desEx.ToString());
            }
        }

19 Source : ExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void ThrottlingException_ShouldBeSerializable()
        {
            var ex = new ThrottlingException("Throttling rate limit quota violation. Quota limit exceeded.", 100, TimeSpan.FromHours(1), DateTime.Today.AddDays(1));

            TestOutput.WriteLine(ex.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, ex);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as ThrottlingException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(ex.StatusCode, desEx.StatusCode);
                replacedert.Equal(ex.Message, desEx.Message);
                replacedert.Equal(ex.Delta, desEx.Delta);
                replacedert.Equal(ex.Reset, desEx.Reset);
                replacedert.Equal(ex.RateLimit, desEx.RateLimit);
                replacedert.Equal(ex.ToString(), desEx.ToString());
            }
        }

19 Source : ConflictExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf409()
        {
            var sut = new ConflictException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as ConflictException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete 
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status409Conflict, sut.StatusCode);
        }

19 Source : PreconditionRequiredExceptionTest.cs
with MIT License
from gimlichael

[Fact]
        public void Ctor_ShouldBeSerializableAndHaveCorrectStatusCodeOf412()
        {
            var sut = new PreconditionRequiredException();

            TestOutput.WriteLine(sut.ToString());

            var bf = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                bf.Serialize(ms, sut);
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                ms.Position = 0;
#pragma warning disable SYSLIB0011 // Type or member is obsolete
                var desEx = bf.Deserialize(ms) as PreconditionRequiredException;
#pragma warning restore SYSLIB0011 // Type or member is obsolete
                replacedert.Equal(sut.StatusCode, desEx.StatusCode);
                replacedert.Equal(sut.ReasonPhrase, desEx.ReasonPhrase);
                replacedert.Equal(sut.Message, desEx.Message);
                replacedert.Equal(sut.ToString(), desEx.ToString());
            }

            replacedert.Equal(StatusCodes.Status428PreconditionRequired, sut.StatusCode);
        }

See More Examples