Skip to content

Commit 3986b4b

Browse files
committed
Add single exe launcher project in examples folder.
1 parent 5f95517 commit 3986b4b

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

examples/LSLExamples.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<!-- All-in-one example project.
3+
It contains a launcher for all examples in the subdirectories that
4+
compiles to a single .exe, prints some information about the wrapper and
5+
passes all arguments through to the example specified as first command line
6+
argument. -->
7+
<PropertyGroup>
8+
<TargetFramework>netcoreapp5.0</TargetFramework>
9+
<Product>Labstreaminglayer C# examples</Product>
10+
<Version>1.14</Version>
11+
<LangVersion>8.0</LangVersion>
12+
<OutputType>Exe</OutputType>
13+
<StartupObject>LSLExamples.EntryPoint</StartupObject>
14+
</PropertyGroup>
15+
<ItemGroup>
16+
<ProjectReference Include="..\liblsl.csproj" />
17+
</ItemGroup>
18+
</Project>

examples/Main.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
5+
namespace LSLExamples
6+
{
7+
static class EntryPoint
8+
{
9+
public static void Main(string[] args) {
10+
var examples = Assembly.GetExecutingAssembly().GetTypes()
11+
.Where(t => t.Namespace =="LSLExamples").ToDictionary(e=>e.Name, e=>e);
12+
13+
var WrapperVersion = Assembly.GetAssembly(typeof(LSL.LSL)).GetName().Version.ToString();
14+
Console.Out.Write("Wrapper version: ");
15+
Console.Out.WriteLine(WrapperVersion);
16+
Console.Out.Write("liblsl version: ");
17+
Console.Out.WriteLine(LSL.LSL.library_version());
18+
if (args.Length < 1 || !examples.ContainsKey(args[0])) {
19+
Console.Out.WriteLine("\nNot enough arguments. Valid examples:");
20+
foreach(var name in examples.Keys) Console.Out.WriteLine(name);
21+
return;
22+
}
23+
var method = examples[args[0]].GetMethod("Main", BindingFlags.Public|BindingFlags.Static);
24+
Console.Out.WriteLine(method);
25+
method.Invoke(null, new object[]{ args});
26+
}
27+
}
28+
}
29+

0 commit comments

Comments
 (0)