Mar*_*cel 1 .net c# conditional-compilation .net-core
我目前正在构建一个.NET程序集,该程序应在.NET 4.5和至少两个.NET Core版本(.NET Core 2.1和.NET Core 3.0)中工作。
我正在使用条件编译,如下所示:
#if NET45
//Use as System.Web.HttpContext
isHttps = context.Request.IsSecureConnection;
IPAddress fromIp = IPAddress.Parse(context.Request.UserHostAddress);
string path = context.Request.Path;
#elif NETCOREAPP2_1
//Use as Microsoft.AspNetCore.Http.HttpContext
isHttps = context.Request.IsHttps;
IPAddress fromIp = context.Request.HttpContext.Request.HttpContext.Connection.RemoteIpAddress;
string path = context.Request.Path;
#elif NETCOREAPP3_0
//Use as Microsoft.AspNetCore.Http.HttpContext
isHttps = context.Request.IsHttps;
IPAddress fromIp = context.Request.HttpContext.Request.HttpContext.Connection.RemoteIpAddress;
string path = context.Request.Path;
#endif
Run Code Online (Sandbox Code Playgroud)
由于NETCOREAPP2_1和NETCOREAPP3_0的代码相同,所以我想知道我可以使用以下代码:
#if NET45
//...
#elif NETCOREAPP2_1 [OR] NETCOREAPP3_0
//...
#endif
Run Code Online (Sandbox Code Playgroud)
但是,此语法不起作用。
在这样的条件编译中是否存在有效的语法来包含OR运算符?
注意:由于这涉及ASP.NET请求管道,因此我认为.NET Standard不是一个选择。您可能需要及时查看代码:https : //github.com/suterma/SqlSyringe/blob/f7df15e2c40a591b8cea24389a1ba8282eb02f6c/SqlSyringe/Syringe.cs
就在这里。与标准中的相同if:
#if NET45
// ...
#elif (NETCOREAPP2_1 || NETCOREAPP3_0)
// ...
#endif
Run Code Online (Sandbox Code Playgroud)
此处更多内容:https : //docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if
| 归档时间: |
|
| 查看次数: |
61 次 |
| 最近记录: |