visual studio - ConvertAll (UWP C#)
本文关键字:UWP ConvertAll studio visual | 更新日期: 2023-09-27 18:01:58
我正在为Windows 10 UWP(c#)编写应用程序
我有问题
我有这个代码
private string GenerateSignature(Dictionary<string, string> parameters, string method, string endpoint)
{
var baserequesturi = Regex.Replace(System.Net.WebUtility.HtmlEncode(this.ApiUrl + endpoint), "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper());
var normalized = NormalizeParameters(parameters);
var signingstring = string.Format("{0}&{1}&{2}", method, baserequesturi,
string.Join("%26", normalized.OrderBy(x => x.Key).ToList().ConvertAll(x => x.Key + "%3D" + x.Value)));
var signature =
Convert.ToBase64String(HashHMAC(Encoding.UTF8.GetBytes(this.ConsumerSecret),
Encoding.UTF8.GetBytes(signingstring)));
Debug.WriteLine(signature);
return signature;
}
但是.ConvertAll
显示这个错误
Severity Code Description Project File Line Suppression State
Error CS0029 Cannot implicitly convert type 'System.Threading.Tasks.Task<string>' to 'string' Milano C:'Users'nemes'Documents'GitHub'Milano_pizza'Milano'MainPage.xaml.cs 41 Active
我需要如何重写代码来解决这个问题?
谢谢的
var baserequesturi = Regex.Replace(System.Net.WebUtility.HtmlEncode(this.ApiUrl + endpoint), "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper());
var normalized = NormalizeParameters(parameters);
NormalizeParameters
private Dictionary<string, string> NormalizeParameters(Dictionary<string, string> parameters)
{
var result = new Dictionary<string, string>();
foreach (var pair in parameters)
{
var key = System.Net.WebUtility.HtmlEncode(System.Net.WebUtility.HtmlDecode(pair.Key));
key = Regex.Replace(key, "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper()).Replace("%", "%25");
var value = System.Net.WebUtility.HtmlEncode(System.Net.WebUtility.HtmlDecode(pair.Value));
value = Regex.Replace(value, "(%[0-9a-f][0-9a-f])", c => c.Value.ToUpper()).Replace("%", "%25");
result.Add(key, value);
}
return result;
}
只需使用标准的Select
而不是特定于列表的ConvertAll
。