-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSamplesLoader.cs
More file actions
32 lines (28 loc) · 1.19 KB
/
SamplesLoader.cs
File metadata and controls
32 lines (28 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace SourceGeneratorPlayground
{
public static class SamplesLoader
{
public static string[] Samples = GetSamples().ToArray();
private static IEnumerable<string> GetSamples()
{
yield return " - None - ";
foreach (string name in typeof(SamplesLoader).Assembly.GetManifestResourceNames())
{
if (name.StartsWith("SourceGeneratorPlayground.Samples") && name.EndsWith(".Generator.cs"))
{
yield return name.Split(".")[2];
}
}
}
public static (string, string) LoadSample(int index)
{
string name = Samples[index];
using var streamReader = new StreamReader(typeof(SamplesLoader).Assembly.GetManifestResourceStream("SourceGeneratorPlayground.Samples." + name + ".Program.cs")!);
using var streamReader1 = new StreamReader(typeof(SamplesLoader).Assembly.GetManifestResourceStream("SourceGeneratorPlayground.Samples." + name + ".Generator.cs")!);
return (streamReader.ReadToEnd(), streamReader1.ReadToEnd());
}
}
}