本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.ToDictionary方法的具体用法?C# NameValueCollection.ToDictionary怎么用?C# NameValueCollection.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.ToDictionary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public void Validate(NameValueCollection parameters)
{
////appid验证
string appid = parameters.ValidateRequired(TopClient.API_KEY);
if (appid != APPID)
{
throw new TopException(102, TopClient.API_KEY + " error");
}
//允许客户端请求时间误差为6分钟。
ulong timestamp = ulong.Parse(parameters.ValidateRequired(TopClient.TIMESTAMP));
DateTime dt = TopUtils.UnixTimeStampToDateTime(timestamp);
double totalMinutes = (DateTime.Now - dt).TotalMinutes;
if (Math.Abs(totalMinutes) > 6)
{
throw new TopException(102, TopClient.TIMESTAMP + " error");
}
//签名验证
string psign = parameters.ValidateRequired(TopClient.SIGN);
var dic = parameters.ToDictionary();
dic.Remove(TopClient.SIGN);
string sign = TopUtils.SignTopRequest(dic, APPSECRET);
if (!string.Equals(sign, psign, StringComparison.OrdinalIgnoreCase))
{
throw new TopException(102, TopClient.SIGN + " error");
}
}
示例2: Returns_an_empty_dictionary_for_an_empty_name_value_collection
public static void Returns_an_empty_dictionary_for_an_empty_name_value_collection()
{
var emptyCollection = new NameValueCollection();
Dictionary<string, string> dictionary = emptyCollection.ToDictionary();
dictionary.Should().BeEmpty();
}
示例3: BuildErrorJson
public static string BuildErrorJson(string type_name, string err_msg, NameValueCollection col)
{
var item = new
{
api_name = type_name,
err_msg = err_msg,
query = col.ToDictionary().ToJson(),
};
return item.ToJson();
}
示例4: ToDictionary
public void ToDictionary()
{
// Type
var @this = new NameValueCollection {{"Fizz", "Buzz"}};
// Exemples
IDictionary<string, object> result = @this.ToDictionary(); // return a Dictionary;
// Unit Test
Assert.AreEqual("Buzz", result["Fizz"]);
}
示例5: TestExtension_NameValueCollectionToDictionaryTest
public void TestExtension_NameValueCollectionToDictionaryTest()
{
var nvc = new NameValueCollection()
{
{ "key1", "val1" },
{ "key2", "val2" },
{ "key3", "val3" },
{ "key4", "val4" },
{ "key5", "val5" },
};
var dict = nvc.ToDictionary();
Assert.IsTrue(dict.ContainsKey("key3"));
}
示例6: ToDictionary_can_convert_to_dictionary_from_NameValueCollection
public void ToDictionary_can_convert_to_dictionary_from_NameValueCollection()
{
var nameValue = new NameValueCollection
{
{"KEY1", "Value1" },
{"Key2", "VALUE2" },
{"kEy3", "vALuE3" }
};
var dic = nameValue.ToDictionary();
Assert.AreEqual("value1", dic["key1"]);
Assert.AreEqual("value2", dic["key2"]);
Assert.AreEqual("value3", dic["key3"]);
}
示例7: Returned_dictionary_contains_exactly_the_elements_from_the_name_value_collection
public static void Returned_dictionary_contains_exactly_the_elements_from_the_name_value_collection()
{
var collection = new NameValueCollection
{
{ "a", "1" },
{ "b", "2" },
{ "c", "3" }
};
Dictionary<string, string> dictionary = collection.ToDictionary();
dictionary.Should().Equal(new Dictionary<string, string>
{
{ "a", "1" },
{ "b", "2" },
{ "c", "3" }
});
}
示例8: GetInstance
public FacebookInstance GetInstance(FacebookConfigElement elem, NameValueCollection paramCollection)
{
string signed_request = paramCollection["signed_request"].Default().DecodeUrl();
FacebookInstance instance = null;
string json = null;
if (!signed_request.isEmpty())
{
#region check the signature of the signed request
string hash = signed_request.Part('.', 0).Decode64();
json = signed_request.Part('.', 1).Decode64();
string evidence = signed_request.Part('.', 1).HashForKey(elem.appSecret);
if (hash.NotEquals(evidence))
throw new FormatException("Invalid Signature");
#endregion
}
instance = new FacebookInstance(elem, json);
instance.HttpParameters = paramCollection.ToDictionary();
return instance;
}
示例9: ToDictionaryWithSkippedNullKey
public void ToDictionaryWithSkippedNullKey() {
NameValueCollection nvc = new NameValueCollection();
nvc[null] = "a";
nvc["b"] = "c";
var dictionary = nvc.ToDictionary(false);
Assert.AreEqual(1, dictionary.Count);
Assert.AreEqual(nvc["b"], dictionary["b"]);
}
示例10: ToDictionaryWithNullKey
public void ToDictionaryWithNullKey() {
NameValueCollection nvc = new NameValueCollection();
nvc[null] = "a";
nvc["b"] = "c";
nvc.ToDictionary(true);
}
示例11: CreateRecord
public static EntityRecord CreateRecord(
this Entity entity,
NameValueCollection request,
string prefix = "",
Func<object, object> valueMutator = null)
{
return entity.CreateRecord(
request.ToDictionary().ToDictionary(x => x.Key, x => (object)x.Value),
prefix,
valueMutator);
}
示例12: ToDictionary_NameValueCollection_CaseInsensitiveKeys
public void ToDictionary_NameValueCollection_CaseInsensitiveKeys()
{
NameValueCollection nameValueCollection = new NameValueCollection();
// Add the values using mixed case and upper case keys even though NameValueCollections are case insensitive
nameValueCollection.Set("Keyname", Random.Next().ToString(CultureInfo.InvariantCulture));
nameValueCollection.Set("KEYNAME", Random.Next().ToString(CultureInfo.InvariantCulture));
Dictionary<string, string> dict = nameValueCollection.ToDictionary();
Assert.IsTrue(
dict.ContainsKey("keyname"),
"After converting a NameValueCollection with ToDictionary, the keys should be case insensitive.");
Assert.AreEqual(
nameValueCollection.Get("keyname"),
dict["keyname"],
"After converting a nameValueCollection with ToDictionary, the keys should be case insensitive.");
Assert.IsTrue(
dict.ContainsKey("Keyname"),
"After converting a NameValueCollection with ToDictionary, the keys should be case insensitive.");
Assert.IsTrue(
dict.ContainsKey("KEYNAME"),
"After converting a NameValueCollection with ToDictionary, the keys should be case insensitive.");
}
示例13: ToDictionary_NameValueCollection_ValuesMatch
public void ToDictionary_NameValueCollection_ValuesMatch()
{
NameValueCollection nameValueCollection = new NameValueCollection();
int count = Random.Next(5, 10);
for (int i = 0; i < count; i++)
nameValueCollection.Set(
String.Format("{1} {0}", i, Random.Next()),
Random.Next().ToString(CultureInfo.InvariantCulture));
Dictionary<string, string> dict = nameValueCollection.ToDictionary();
foreach (string key in nameValueCollection)
Assert.AreEqual(
nameValueCollection.Get(key),
dict[key],
"After converting a nameValueCollection with ToDictionary, the values of each key should be preserved.");
}
示例14: ToDictionary_NameValueCollection_HasSameItemCount
public void ToDictionary_NameValueCollection_HasSameItemCount()
{
NameValueCollection nameValueCollection = new NameValueCollection();
int count = Random.Next(1, 20);
for (int i = 0; i < count; i++)
nameValueCollection.Set(
String.Format("{1} {0}", i, Random.Next()),
Random.Next().ToString(CultureInfo.InvariantCulture));
Dictionary<string, string> dict = nameValueCollection.ToDictionary();
Assert.AreEqual(
nameValueCollection.Count,
dict.Count,
"Converting a nameValueCollection with ToDictionary should preserve item count");
}
示例15: ToDictionary_EmptyNameValueCollection_GivesEmptyDict
public void ToDictionary_EmptyNameValueCollection_GivesEmptyDict()
{
NameValueCollection nameValueCollection = new NameValueCollection();
Dictionary<string, string> dict = nameValueCollection.ToDictionary();
Assert.AreEqual(
0,
dict.Count,
"Converting an empty nameValueCollection with ToDictionary should result in an empty dictionary");
}