在F#中,如何创建自定义属性以应用于表达式?我到处寻找资源,但我一无所获.
例如,该属性[<Entrypoint>]可以应用于某个表达式,因此编译器可以推断该表达式应该是类型array string -> int.
如何创建自定义属性以使用simillary?
我想知道以功能方式与F#中的C#代码交互的最佳方式,当我必须多次检查null时.
从C#开始,很简单,因为我有空操作符
public bool Authorize(DashboardContext dashboardContext)
{
var context = new OwinContext(dashboardContext.GetOwinEnvironment());
var user = context.Authentication.User;
return user?.Identity?.IsAuthenticated ?? false;
}
Run Code Online (Sandbox Code Playgroud)
从F#开始,我做到了这一点
let authorize (ctx:DashboardContext) =
match OwinContext(ctx.GetOwinEnvironment()) with
| null -> false
| c -> match c.Authentication.User with
| null -> false
| user -> user.Identity.IsAuthenticated
Run Code Online (Sandbox Code Playgroud)
但我对此并不满意.这样做的功能方法是什么?我想也许一些计算表达式会有所帮助,但我不知道如何完成.
似乎 docker 服务发现仅适用于用户定义的网络,而不适用于默认网桥(docker0),但我在文档中没有找到任何内容。
docker run --rm -d --name c1 alpine sleep 2h
docker run --rm -d --name c2 alpine sleep 2h
docker exec -ti c1 ping c2
它给了我 ping: bad address 'c2'
但是如果我创建一个自定义桥接网络一切正常:
docker network create u-bridge
docker run --rm -d --name u1 --net u-bridge alpine sleep 2h
docker run --rm -d --name u2 --net u-bridge alpine sleep 2h
docker exec -ti u1 ping u2
它给了我: PING u2 (172.18.0.3): 56 data bytes (...)
默认桥接网络不应该有服务发现吗?