BililiveRecorder/test/BililiveRecorder.Flv.RuleTests/SampleFileLoader.cs

24 lines
759 B
C#
Raw Normal View History

2021-11-02 21:46:44 +08:00
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using BililiveRecorder.Flv.Xml;
namespace BililiveRecorder.Flv.RuleTests
{
public static class SampleFileLoader
{
public static XmlFlvFile Load(string fileName)
{
var stackTrace = new StackTrace();
var frames = stackTrace.GetFrames();
var attr = frames.Select(x => x!.GetMethod()!.GetCustomAttribute<SampleFileTestDataAttribute>()).First(x => x is not null);
var fullPath = Path.Combine(attr!.BasePath, fileName);
using var s = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
return (XmlFlvFile)XmlFlvFile.Serializer.Deserialize(s)!;
}
}
}