0

How can I write OS specific code in net core? Like golangs <pkgname>_<osname>.go files.

I tried to solve this problem with RuntimeInformation.IsOSPlatform and if/else blocks, but I don't like it.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Mert Sayın
  • 309
  • 2
  • 7
  • 1
    What do you mean by `OS specific code`, the point of `dot net core` is too be cross-platform so you don't have to code for specific operating system. – Ryan Wilson Feb 19 '19 at 20:20
  • For example: I want to port this `https://github.com/shirou/gopsutil` library for .net core. – Mert Sayın Feb 19 '19 at 20:23
  • Possible duplicate of [dot net core build platform/os specific code or class files](https://stackoverflow.com/questions/39557327/dot-net-core-build-platform-os-specific-code-or-class-files) – Alex Yu Feb 20 '19 at 00:19
  • @RyanWilson I think `OS specific code` is quite clear: you want to code something for one specific OS. An example could be writing to the system event log, which is only available on Windows. `EventLog.WriteEvent()` does not compile unless you tell the compiler to only compile that block of code for Windows or change the target to only compile for Windows. – Mark Feb 24 '21 at 16:14

0 Answers0