forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maint: Fixing the use of the binary formatter in net461 so all unit t…
…ests now pass. (octokit#2535)
- Loading branch information
1 parent
eaef1ee
commit bc156af
Showing
6 changed files
with
65 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.Serialization; | ||
using System.Runtime.Serialization.Formatters.Binary; | ||
|
||
namespace Octokit.Tests.Helpers | ||
{ | ||
public class BinaryFormatterExtensions | ||
{ | ||
public static T SerializeAndDeserializeObject<T>(T input) | ||
{ | ||
using (var stream = new MemoryStream()) | ||
{ | ||
var formatter = new BinaryFormatter(); | ||
formatter.Serialize(stream, input); | ||
stream.Position = 0; | ||
formatter.Binder = new SerializationBinderHelper(); | ||
var deserializedObject = formatter.Deserialize(stream); | ||
var deserialized = (T)deserializedObject; | ||
return deserialized; | ||
} | ||
} | ||
|
||
internal class SerializationBinderHelper : SerializationBinder | ||
{ | ||
public string Name { get; set; } | ||
|
||
public override Type BindToType(string i_AssemblyName, string i_TypeName) | ||
{ | ||
Type typeToDeserialize = Type.GetType(String.Format(" {0}, {1}", i_TypeName, i_AssemblyName)); return typeToDeserialize; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters