简体   繁体   中英

ConvertAll (UWP C#)

I'm writing app for Windows 10 UWP(C#)

I have problem

I have this code

  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;
    }

But .ConvertAll show this error

  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

How I need to rewrite code to solve this problem?

Thank's

UPDATE

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM