//-----------------------------------------------------------------------
//
// Copyright (c) ParanoidMike. All rights reserved.
//
//-----------------------------------------------------------------------
namespace ParanoidMike
{
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.Win32;
///
/// Reusable functions for many uses.
///
public static class Utility
{
///
/// Convert an object to a byte array.
/// Copied from http://snippets.dzone.com/posts/show/3897
///
///
/// The object to be converted.
///
///
/// The byte[] array to which the object is converted.
///
public static byte[] ObjectToByteArray(object obj)
{
if (obj == null)
{
return null;
}
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}