40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
namespace Strata.RxNorm.Biz.Test.Unit.Extensions
|
|
{
|
|
[ExcludeFromCodeCoverage]
|
|
public static class ResourceExtensions
|
|
{
|
|
|
|
public static IEnumerable<string> LoadRxnNorm(this Assembly assembly, string fileName)
|
|
{
|
|
var path = assembly.resourceName(fileName);
|
|
return assembly.ReadAllResourceLines(path);
|
|
}
|
|
|
|
public static string resourceName(this Assembly assembly, string fileName)
|
|
=> assembly.GetManifestResourceNames().Single(str => str.EndsWith(fileName));
|
|
|
|
public static string[] ReadAllResourceLines(this Assembly assembly, string resourceName)
|
|
{
|
|
using Stream stream = assembly.GetManifestResourceStream(resourceName);
|
|
using StreamReader reader = new StreamReader(stream);
|
|
return EnumerateLines(reader).ToArray();
|
|
}
|
|
|
|
public static IEnumerable<string> EnumerateLines(TextReader reader)
|
|
{
|
|
string line;
|
|
|
|
while ((line = reader.ReadLine()) != null)
|
|
{
|
|
yield return line;
|
|
}
|
|
}
|
|
}
|
|
}
|