【发布时间】:2020-02-17 10:46:08
【问题描述】:
我在不同的环境(Windows、OsX 和 Linux)中使用 jsReport 库
在Startup.cs 我使用这段代码来启动库
services.AddJsReport(new LocalReporting()
.UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? JsReportBinary.GetBinary()
: jsreport.Binary.OSX.JsReportBinary.GetBinary()).AsUtility()
.Create());
所以如果不是 Windows 平台,他会寻找 OSX 的二进制文件。
但是当有人在 Linux 上使用项目时,他需要将代码更改为:
services.AddJsReport(new LocalReporting()
.UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? JsReportBinary.GetBinary()
: jsreport.Binary.Linux.JsReportBinary.GetBinary())
如何编写以 Windows 为主的三元条件,如果不是,它将在 OSX 和 Linux 之间进行选择?
【问题讨论】:
-
有没有办法识别操作系统?两个贴出的代码sn-p都有
OSPlatform.Windows查看平台? -
":"后面的"if not"部分可以再写一个三元运算,判断是OSX还是Linux,然后返回对应的。
标签: c# asp.net asp.net-core ternary-operator