父对象和大多数子对象具有异步功能并使用await。StyleCop正在观察,并针对一个儿童班缺乏等待的情况提出了建议。
当您无法删除异步签名时,使StyleCop开心的最佳方法是什么?
例如:
class Program
{
static void Main(string[] args)
{
var t = DownloadSomethingAsync();
Console.WriteLine(t.Result);
}
public delegate Task<string> TheDelegate(string page);
static async Task<string> DownloadSomethingAsync()
{
string page = "http://en.wikipedia.org/";
var content = await GetPageContentAsync(page);
return content;
}
static async Task<string> GetPageContentAsync(string page)
{
string result;
TheDelegate getContent = GetNotOrgContentAsync;
if (page.EndsWith(".org"))
{
getContent = GetOrgContentAsync;
}
result = await getContent(page);
return result;
}
static async Task<string> GetOrgContentAsync(string page)
{
string result;
using (HttpClient client = new HttpClient())
using …Run Code Online (Sandbox Code Playgroud)