小编Rob*_*lls的帖子

像F#中的List一样切片

使用数组,let foo = [|1;2;3;4|]我可以使用以下任何一种方法从数组中返回一个切片.

foo.[..2] 
foo.[1..2] 
foo.[2..]
Run Code Online (Sandbox Code Playgroud)

我如何为List做同样的事情let foo2 = [1;2;3;4]?当我尝试与我得到的数组相同的语法时error FS00039: The field, constructor or member 'GetSlice' is not defined.

获取List子节的首选方法是什么?为什么它们不是为了支持GetSlice而构建的?

f# list slice

17
推荐指数
2
解决办法
4855
查看次数

asp.net mvc azure AAD身份验证无限循环

我有一个带有azure AAD登录的asp.net mvc应用程序.当我按f5调试应用程序转到azure在AAD中进行身份验证时,它会返回到应用程序到控制器,然后重定向回到azure.

我知道这个,因为如果我在登录控制器上放置一个断点,它会无限受到攻击

这是我的路线配置

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //routes.IgnoreRoute("");
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Dashboards", action = "Dashboard_1", id = UrlParameter.Optional }
            );
        }
Run Code Online (Sandbox Code Playgroud)

这是我的仪表板控制器,已授权

[Authorize]
    public class DashboardsController : Controller
    {
        public ActionResult Dashboard_1()
        {
            return View();
        }
Run Code Online (Sandbox Code Playgroud)

这是我的登录和签名帐户控制器操作

public class AccountController : Controller
    {
        public void SignIn()
        {
            if (!Request.IsAuthenticated)
            {
                HttpContext.GetOwinContext().Authentication.Challenge(
                                new AuthenticationProperties { RedirectUri = "/" },
                                OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
        }

        public void SignOut()
        {
            // Remove all …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc owin adal

8
推荐指数
1
解决办法
4000
查看次数

使用Mongodb oplog跟踪数据更改历史记录

我正在寻找使用MongoDB的应用程序.我是MongoDB的新手.我需要跟踪用户对系统所做的更改,添加/更改的内容以及更改时间.oplog似乎包含了我需要的所有数据,在我看来,将oplog的副本持久保存到单独的无上限集合中会给我所需的所有历史记录.它不需要快速检索或立即可用.

这种方法有问题吗?任何人都可以建议存储这些数据的最佳方法吗?

replication mongodb

5
推荐指数
1
解决办法
831
查看次数

从F#中的lambda表达式返回不同类型的数组

我有一份记录清单

type Item = { Color : string; Size : int}
let itemList = [{Color="Red"; Size=1};
                {Color="Green"; Size=2};
                {Color="Blue"; Size=3};]
Run Code Online (Sandbox Code Playgroud)

我希望将我的记录列表转换为一系列值,如[|"Red";"Green";"Blue"|]或[| 1; 2; 3 |]

我可以像这样到达那里

type ItemType =
| Color of string
| Size of int

type ItemEnum =
| C
| S

let GetProp x y =
match x with
| C -> List.toArray y |> Array.map(fun x -> ItemType.Color(x.Color))
| S -> List.toArray y |> Array.map(fun x -> ItemType.Size(x.Size))
Run Code Online (Sandbox Code Playgroud)

但是当我打电话的时候GetProp S itemList我会回来[|尺寸1; 尺寸2; 大小3 |].有用,但不完全是我正在寻找的. …

arrays lambda f# types record

1
推荐指数
1
解决办法
420
查看次数

从F#中不同类型数组的区别联合获取类型化数组

如果我有不同类型数组的区别联合,我怎么能将它们转换为'实际'类型?

type ItemStuff = 
   | Colors of string[]
   | Sizes of int[]

let foo = Sizes [|1;2;3|]
Run Code Online (Sandbox Code Playgroud)

运行上面的内容后,当我得到foo的值时,我看到:

val foo : ItemStuff = Sizes [|1;2;3|]
Run Code Online (Sandbox Code Playgroud)

如何从foo获取实际的int数组?我只是缺少一些允许我访问类似的语法 foo.[2]吗?我不能通过foo枚举所以我无法使用地图.我可以为ItemStuff编写一个成员,为我返回的每个不同类型的数组返回一个正确类型的数组,但这似乎不正确?

我最好的方法是什么?

这就是我最终做的事情.关于更好的方法的任何想法?

type ItemProp =
| Colors of string[]
| Sizes of int[]
| Quants of int[]
member this.GetColors() =
   match this with
   | Colors (stringArray) ->
       stringArray
   | _ -> null
member this.GetIntArr() =
   match this with
   | Sizes (intArray) | Quants (intArray) ->
       intArray
   |_ -> null

foo.GetIntArr()
Run Code Online (Sandbox Code Playgroud)

arrays f# discriminated-union

1
推荐指数
1
解决办法
519
查看次数