object를 byte 로, byte를 struct로 변환하는 코드입니다.
public static object ByteToObject(byte[] buffer)
{
try
{
using (MemoryStream stream = new MemoryStream(buffer))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
stream.Position = 0;
return binaryFormatter.Deserialize(stream);
}
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
return null;
}
public static byte[] ObjectToByte(object obj)
{
try
{
using (MemoryStream stream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, obj);
return stream.ToArray();
}
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
return null;
}
'Languages > C#' 카테고리의 다른 글
| [ C# ] Change Audio Device (0) | 2013.08.06 |
|---|---|
| [ C# ] FTP (4) | 2013.02.26 |
| [ C# ] Struct To Byte, Byte To Struct (0) | 2012.08.17 |
| [ C# ] Win32 API MouseEvent (8) | 2010.12.07 |
| [ C# ] C# FTP Download (3) | 2010.07.21 |
