Mercurial > hg > Database > jungle-sharp
annotate Main/ObjectMapper/ConvertObject.cs @ 38:e954d456665c
library is made by rake
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 22 Feb 2017 16:58:10 +0900 |
parents | 1f99e150f336 |
children |
rev | line source |
---|---|
38
e954d456665c
library is made by rake
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
20
diff
changeset
|
1 // using UnityEngine; |
20 | 2 using System.Collections; |
3 using System; | |
4 using System.Runtime.Serialization.Formatters.Binary; | |
5 using System.Runtime.Serialization; | |
6 using System.IO; | |
7 [Serializable] | |
8 public class ConvertObject : MonoBehaviour { | |
9 | |
10 public static byte[] Convert (object target) { | |
11 IFormatter formatter = new BinaryFormatter(); | |
12 MemoryStream ms = new MemoryStream(); | |
13 formatter.Serialize(ms, target); | |
14 byte[] myByteArray = ms.ToArray(); | |
15 return myByteArray; | |
16 } | |
17 | |
18 public static object UnConvert(byte[] target) { | |
19 using (var memStream = new MemoryStream()) | |
20 { | |
21 var binForm = new BinaryFormatter(); | |
22 memStream.Write(target, 0, target.Length); | |
23 memStream.Seek(0, SeekOrigin.Begin); | |
24 var obj = binForm.Deserialize(memStream); | |
25 return obj; | |
26 } | |
27 } | |
28 } |