Created
August 18, 2013 15:33
-
-
Save yemrekeskin/6262236 to your computer and use it in GitHub Desktop.
ObjecSerilizator generic class for object serilization
This file contains hidden or 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
| public static class ObjSerilizator | |
| { | |
| public static TData DeserializeFromString<TData>(string settings) | |
| { | |
| byte[] b = Convert.FromBase64String(settings); | |
| using (var stream = new MemoryStream(b)) | |
| { | |
| var formatter = new BinaryFormatter(); | |
| stream.Seek(0, SeekOrigin.Begin); | |
| return (TData)formatter.Deserialize(stream); | |
| } | |
| } | |
| public static string SerializeToString<TData>(TData settings) | |
| { | |
| using (var stream = new MemoryStream()) | |
| { | |
| var formatter = new BinaryFormatter(); | |
| formatter.Serialize(stream, settings); | |
| stream.Flush(); | |
| stream.Position = 0; | |
| return Convert.ToBase64String(stream.ToArray()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment