小编Jos*_*den的帖子

使用在C#中声明的虚拟异步任务并在F#中覆盖它

目前我有一段用C#编写的代码,它被一段F#代码用作.NET库.这是问题:

假设我在C#库中有以下类:

namespace Jaxrtech.Logic
{
    public class Initializer
    {
        public Initializer()
        {
        }

        public async Task Setup()
        {
            // Run implementation independed setup here

            // Now call the implementation specific override
            await OnSetup();

            // Do any additional setup after the implemntation specific stuff
        }

        // Allow for custom setup tasks to be ran by the Initializer
        protected virtual async Task OnSetup()
        {
            // Return a completed task by default
            await Task.FromResult(0);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在F#中覆盖,如下:

open System.Threading.Tasks
open Jaxrtech.Logic

type …
Run Code Online (Sandbox Code Playgroud)

.net c# f# asynchronous async-await

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

标签 统计

.net ×1

async-await ×1

asynchronous ×1

c# ×1

f# ×1