Define for Os version in C#

前端 未结 2 1264
醉梦人生
醉梦人生 2021-01-25 10:55

I have a problem, I cannot find a way to detect windows version at compilation time.

My purpose is to create an executable that depend on Interface, which are defined on

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-25 11:16

    You should really turn this around. It is better to solve this at runtime. What you can do:

    • Create an interface that defines the actions you want to perform;
    • Create separate implementations for different platforms (in your sample there would be a Windows10Implementation class, which calls INetFwRule3);
    • Then, in your code, check for Environment.OSVersion and create the implementation class for that specific platform.

    If necessary, you can split off the implementations in separate class libraries, so you don't always have to load OS specific stuff, but only when you need it.

提交回复
热议问题