Reputation: 1391
Specifically, what I need to identify is the calling development platform (i.e. .NET Core vs. .NET Framework vs. Other) rather than the operating system information I can get through System.Environment.OperatingSystem.Platform. Is there a way to do this?
(To give more detail on my specific use case, I am referencing a library - log4net - which is configured by passing it an XML resource. Some of its configurable features which I want to use if available are supported under .NET Framework but not under .NET Core, and I want to be able therefore to pass it a different version of the resource depending on which I'm being used by.)
Upvotes: 2
Views: 711
Reputation: 43188
I had to do this once. There was a method I needed to call that varied across implementations. I just used reflection to try one name after another.
Trying to detect the runtime library is silly. Detect the differences directly. It's less likely to break.
Upvotes: 0
Reputation: 2265
Solving from the runtime environment could prove to be uncertain as runtime change. I would force the issue up front before the application runs. As previously stated you could pass in the runtime or configure it.
Another option would be something similar to SL4J provides. Runtime determination dependent upon how you deploy the application.
You could create your own interface for exposing platform information. Then, at deploy time, just add the appropriate assembly to the installation. Load the assembly and call the methods you require.
Alternatively you see how Microsoft handled similar situations here: https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/
Upvotes: 1