1
0
mirror of synced 2024-12-04 20:08:00 +01:00
Switch-Toolbox/Switch_Toolbox_Library/IO/Extensions/ByteArrayExtensions.cs

33 lines
910 B
C#
Raw Normal View History

2019-07-01 00:24:23 +02:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading.Tasks;
namespace System
{
public static class ByteArrayExtensions
{
public static T[] Slice<T>(this T[] arr, uint indexFrom, uint size)
{
T[] result = new T[size];
Array.Copy(arr, indexFrom, result, 0, size);
return result;
}
public static T[] SubArrayDeepClone<T>(this T[] data, int index, int length)
{
T[] arrCopy = new T[length];
Array.Copy(data, index, arrCopy, 0, length);
using (MemoryStream ms = new MemoryStream())
{
var bf = new BinaryFormatter();
bf.Serialize(ms, arrCopy);
ms.Position = 0;
return (T[])bf.Deserialize(ms);
}
}
}
}