mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
29 lines
637 B
C#
29 lines
637 B
C#
using System.Collections;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace AssetRipper.Tests;
|
|
|
|
internal sealed class RandomStructEnumerable<T> : IEnumerable<T> where T : unmanaged
|
|
{
|
|
private byte[] Data { get; }
|
|
public int Count { get; }
|
|
|
|
public RandomStructEnumerable(int count)
|
|
{
|
|
Count = count;
|
|
Data = new byte[Unsafe.SizeOf<T>()];
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
for (int i = Count; i > 0; i--)
|
|
{
|
|
TestContext.CurrentContext.Random.NextBytes(Data);
|
|
yield return MemoryMarshal.Read<T>(Data);
|
|
}
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
}
|