我想知道在一個功能性的方式與F#C#代碼交互的最佳方式時,當我要檢查空多次做廣泛null檢查在F#中的最佳方式。什麼是調用C#代碼
從C#,很簡單,因爲我有空操作
public bool Authorize(DashboardContext dashboardContext)
{
var context = new OwinContext(dashboardContext.GetOwinEnvironment());
var user = context.Authentication.User;
return user?.Identity?.IsAuthenticated ?? false;
}
從F#,我做了這個
let authorize (ctx:DashboardContext) =
match OwinContext(ctx.GetOwinEnvironment()) with
| null -> false
| c -> match c.Authentication.User with
| null -> false
| user -> user.Identity.IsAuthenticated
但我不滿意這個。做這件事的功能是什麼?我想也許一些計算表達式會有所幫助,但我不知道如何完成。
您的解決方案看起來很好,這個用例。 – s952163