Skip to content

Commit 5751a57

Browse files
committed
Remove compile time constants
1 parent 5faf9c7 commit 5751a57

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

Rubjerg.Graphviz/Constants.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
public static class NativeLibraryNames
5+
{
6+
public static string GvcLib => _gvcLib.Value;
7+
public static string CGraphLib => _cgraphLib.Value;
8+
public static string XDotLib => _xdotLib.Value;
9+
public static string GraphvizWrapperLib => _wrapperLib.Value;
10+
11+
private static readonly Lazy<string> _gvcLib = new(() => Resolve("gvc.dll", "libgvc.so.6"));
12+
private static readonly Lazy<string> _cgraphLib = new(() => Resolve("cgraph.dll", "libcgraph.so.6"));
13+
private static readonly Lazy<string> _xdotLib = new(() => Resolve("xdot.dll", "libxdot.so.4"));
14+
private static readonly Lazy<string> _wrapperLib = new(() => Resolve("GraphvizWrapper.dll", "libGraphvizWrapper.so"));
15+
16+
private static string Resolve(string windows, string linux, string? mac = null)
17+
{
18+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return windows;
19+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return linux;
20+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return mac ?? throw new PlatformNotSupportedException("macOS not supported yet.");
21+
throw new PlatformNotSupportedException("Unknown platform");
22+
}
23+
}

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test-all: build-tests
5050
just test Rubjerg.Graphviz.TransitiveTest/Rubjerg.Graphviz.TransitiveTest.csproj
5151

5252
# Run the nuget.org tests
53-
test-nugetorg: build-tests
53+
test-nugetorg:
5454
dotnet tool restore
5555
dotnet restore NugetOrgTests/Rubjerg.Graphviz.NugetOrgTests.sln
5656
just build NugetOrgTests/Rubjerg.Graphviz.NugetOrgTests.sln

0 commit comments

Comments
 (0)