-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathProgram.cs
33 lines (26 loc) · 830 Bytes
/
Program.cs
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
33
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Drone;
internal static class Program
{
public static async Task Main(string[] args)
{
var bytes = await GetEmbeddedResource("drone");
var asm = Assembly.Load(bytes);
var task = (Task)asm.GetType("Drone.Program")!.GetMethod("Execute")!.Invoke(null, Array.Empty<object>());
await task;
}
private static async Task<byte[]> GetEmbeddedResource(string name)
{
var self = Assembly.GetExecutingAssembly();
using var rs = self.GetManifestResourceStream(name);
if (rs is null)
return Array.Empty<byte>();
using var ms = new MemoryStream();
await rs.CopyToAsync(ms);
return ms.ToArray();
}
}