[英]ConvertAll (UWP C#)
我正在为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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.