本文整理汇总了C#中Dictionary.ToQueryString方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.ToQueryString方法的具体用法?C# Dictionary.ToQueryString怎么用?C# Dictionary.ToQueryString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.ToQueryString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSuggestSimilarDocumentsAsync
public async Task<IEnumerable<Models.Products.ProductSuggestItemOutputModel>> GetSuggestSimilarDocumentsAsync(int id, string offerType = null, string domainLanguage = "fr", int take = 3)
{
using (var dclient = this.CreateClient())
{
var client = dclient.Client;
var parameters = new Dictionary<string, string>();
var dico = new Dictionary<string, string>(){
{ "domainLanguage", domainLanguage },
{ "take", take.ToString() },
{ "offerType", offerType }
};
var queryString = dico.ToQueryString();
var url = "api/v2/products/{id}/suggests/similar".Replace("{id}", id.ToString());
if (!string.IsNullOrEmpty(queryString))
url = url + "?" + queryString;
var response = await client.GetAsync(this.GetUri(url)).ConfigureAwait(false);
await this.HandleResponseAsync(response).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
return (await this.GetObjectAsync<IEnumerable<Models.Products.ProductSuggestItemOutputModel>>(response.Content).ConfigureAwait(false));
return Enumerable.Empty<Models.Products.ProductSuggestItemOutputModel>();
}
}
示例2: ToString
public override string ToString()
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
if (Lat.HasValue && Lon.HasValue)
{
parameters.Add("cp", string.Format("{0}~{1}", Lat.Value, Lon.Value));
}
if (Zoom.HasValue)
{
parameters.Add("lvl", Zoom.Value.ToString());
}
if (!String.IsNullOrWhiteSpace(Query))
{
parameters.Add("q", Query);
}
if (!String.IsNullOrWhiteSpace(Where))
{
parameters.Add("where", Where);
}
if (TrafficOn.HasValue)
{
parameters.Add("trfc", TrafficOn.Value ? "1" : "0");
}
if (RoadView.HasValue)
{
parameters.Add("sty", RoadView.Value ? "r" : "a");
}
return parameters.ToQueryString("bingmaps://dreamteam-mobile.com/");
}
示例3: ToQueryString
public void ToQueryString()
{
var Collection = new Dictionary<string, string>();
Collection.Add("A", "1");
Collection.Add("B", "2");
Assert.Equal("?A=1&B=2", Collection.ToQueryString());
}
示例4: AuthASync
public async Task<RootAuth> AuthASync(string login, string password)
{
var postData = new Dictionary<string, string>();
postData.Add("login", login);
var md5Password = MD5CryptoServiceProvider.GetMd5String(password);
postData.Add("password", md5Password);
var options = "?" + postData.ToQueryString();
RootAuth response;
try
{
response = await Post<RootAuth>(AuthUrl + options, null);
ValidateResponse(response);
}
catch (ConnectionException ex)
{
if (!string.IsNullOrEmpty(ex.ResponseContent))
ValidateResponse(ex.ResponseContent);
throw;
}
return response;
}
示例5: GetEpisodePictureASync
public async Task<byte[]> GetEpisodePictureASync(int episodeId, int width, int height)
{
var postData = new Dictionary<string, string>();
postData.Add("id", episodeId);
if (width != 0)
postData.Add("width", width);
if (height != 0)
postData.Add("height", height);
postData.Add("picked", "show");
var options = "?" + postData.ToQueryString();
var response = await Get(EpisodeUrl + options);
if (response.StatusCode == HttpStatusCode.NotFound)
return null;
var stream = await response.Content.ReadAsBufferAsync();
var byteArray = stream.ToArray();
return byteArray.Length == 0 ? null : byteArray;
}
示例6: ToQueryStringOneValue
public void ToQueryStringOneValue()
{
var dict = new Dictionary<string, string>();
dict["foo"] = "bar";
Assert.AreEqual("?foo=bar",
dict.ToQueryString());
}
示例7: ToQueryStringUnsafeValues
public void ToQueryStringUnsafeValues()
{
var dict = new Dictionary<string, string>();
dict["foo"] = "#?&%=";
Assert.AreEqual("?foo=%23%3F%26%25%3D",
dict.ToQueryString());
}
示例8: PostBytes
/// <summary>
/// transform a dictionary into the query string that is translated in byte array then
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
public static byte[] PostBytes(Dictionary<string, string> items)
{
if (items == null || !items.Any())
return null;
var bytes = Encoding.UTF8.GetBytes(items.ToQueryString());
return bytes.Any() ? bytes : null;
}
示例9: ToQueryStringTwoValues
public void ToQueryStringTwoValues()
{
var dict = new Dictionary<string, string>();
dict["foo"] = "bar";
dict["ba"] = "zinga";
Assert.AreEqual("?foo=bar&ba=zinga",
dict.ToQueryString());
}
示例10: should_convert_string_dictionary_to_query_string
public void should_convert_string_dictionary_to_query_string()
{
var values = new Dictionary<string, string> {
{"key1", "value1"},
{"key2", "value2"}
};
values.ToQueryString().Should().Be("key1=value1&key2=value2");
}
示例11: should_encode_values
public void should_encode_values()
{
var values = new Dictionary<string, string> {
{"name", "John Smith"},
{"email", "[email protected]"}
};
values.ToQueryString(encode: true)
.Should().Be("name=John+Smith&email=email%40website.com");
}
示例12: should_override_default_delimiters_when_writing
public void should_override_default_delimiters_when_writing()
{
var values = new Dictionary<string, string> {
{"key1", "value1"},
{"key2", "value2"}
};
values.ToQueryString(paramDelimiter: ' ', valueDelimiter: '@')
.Should().Be("[email protected] [email protected]");
}
示例13: InitContent
public static void InitContent(dynamic viewBag, string nameSpace, string page, Dictionary<string, string> dimensions)
{
var repository = new ContentRepository(
new Uri(System.Configuration.ConfigurationManager.AppSettings["NeuCMSServiceURL"])
);
var content = repository.GetViewContents(nameSpace,page, dimensions.ToQueryString()).ToList();
dynamic neuCMSContent = new NeuCMSContent(content);
viewBag.NeuContent = neuCMSContent;
}
示例14: GetObjectUrl
public static string GetObjectUrl(string storageUrl, string containerId, string objectId, Dictionary<string, string> queryParams = null)
{
var url = storageUrl + "/" + containerId.Encode() + "/" + objectId.Encode();
if (queryParams != null)
{
url += queryParams.ToQueryString();
}
return url;
}
示例15: GetAccountUrl
public static string GetAccountUrl(string storageUrl, Dictionary<string, string> queryParams = null)
{
var url = storageUrl;
if (queryParams != null)
{
url += queryParams.ToQueryString();
}
return url;
}