/Languages/KeyValue.cs |
@@ -6,7 +6,10 @@ |
|
using System; |
using System.Collections.Generic; |
using System.IO; |
using System.Linq; |
using System.Text; |
using System.Threading.Tasks; |
|
namespace wasSharp.Languages |
{ |
@@ -102,8 +105,9 @@ |
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
/// Serialises a dictionary to key-value data. |
/// Serializes a dictionary to key-value data. |
/// </summary> |
/// <param name="data">an input string</param> |
/// <returns>a key-value data encoded string</returns> |
public static string Encode(IEnumerable<KeyValuePair<string, string>> data) |
{ |
@@ -111,6 +115,19 @@ |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2018 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
/// Asynchronously serializes a dictionary to key-value data. |
/// </summary> |
/// <param name="data">an input string</param> |
/// <returns>a key-value data encoded string</returns> |
public static string Encode(IEnumerable<KeyValuePair<Task<string>, Task<string>>> data) |
{ |
return string.Join("&", data.AsParallel().Select(o => string.Join("=", o.Key.Result, o.Value.Result))); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
@@ -121,5 +138,17 @@ |
{ |
return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value)); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
/// Escapes a dictionary's keys and values for sending as POST data. |
/// </summary> |
public static IEnumerable<KeyValuePair<Task<string>, Task<string>>> EscapeAsync(IEnumerable<KeyValuePair<string, string>> data, |
Func<string, Task<string>> func) |
{ |
return data.AsParallel().ToDictionary(async o => await func(o.Key), async p => await func(p.Value)); |
} |
} |
} |