ConvertAll(UWP C#)

时间:2016-08-11 07:37:39

标签: c# visual-studio uwp

我正在为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;
    }

1 个答案:

答案 0 :(得分:0)

只需使用标准Select代替特定于列表的ConvertAll