Files
UVtools/PrusaSL1Reader/Extensions/ObjectExtensions.cs
T
Tiago Conceição 788f12cc41 v0.3
2020-04-27 22:56:35 +01:00

37 lines
1.1 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace PrusaSL1Reader.Extensions
{
public static class ObjectExtensions
{
/// <summary>
/// Converts a string into a target type
/// </summary>
/// <typeparam name="T">Target type to convert into</typeparam>
/// <param name="input">Value</param>
/// <returns>Converted value into target type</returns>
public static T Convert<T>(this object input)
{
return StringExtensions.Convert<T>(input.ToString());
}
public static object DeserializeFromBytes(byte[] bytes)
{
var formatter = new BinaryFormatter();
using (var stream = new MemoryStream(bytes))
{
return formatter.Deserialize(stream);
}
}
}
}