当前位置: 首页>>代码示例>>C#>>正文


C# NameValueCollection.ToDictionary方法代码示例

本文整理汇总了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");
            }
        }
开发者ID:ChobitsSP,项目名称:Top.Rest,代码行数:30,代码来源:AuthRequest.cs

示例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();
        }
开发者ID:razormad,项目名称:ExtraLINQ,代码行数:8,代码来源:ToDictionaryTests.cs

示例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();
 }
开发者ID:ChobitsSP,项目名称:Top.Rest,代码行数:10,代码来源:RequestUtils.cs

示例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"]);
        }
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:11,代码来源:NameValueCollection.ToDictionary.cs

示例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"));
        }
开发者ID:deepcovelabs,项目名称:raven-sdk-dotnet,代码行数:14,代码来源:UtilExtensionsTests.cs

示例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"]);
        }
开发者ID:vanthoainguyen,项目名称:Flatwhite,代码行数:15,代码来源:ExtensionMethodsTests.cs

示例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" }
            });
        }
开发者ID:razormad,项目名称:ExtraLINQ,代码行数:18,代码来源:ToDictionaryTests.cs

示例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;
        }
开发者ID:keith9820,项目名称:Groundfloor,代码行数:21,代码来源:FacebookFactory.cs

示例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"]);
		}
开发者ID:randalls,项目名称:DotNetOpenAuth,代码行数:8,代码来源:MessagingUtilitiesTests.cs

示例10: ToDictionaryWithNullKey

		public void ToDictionaryWithNullKey() {
			NameValueCollection nvc = new NameValueCollection();
			nvc[null] = "a";
			nvc["b"] = "c";
			nvc.ToDictionary(true);
		}
开发者ID:randalls,项目名称:DotNetOpenAuth,代码行数:6,代码来源:MessagingUtilitiesTests.cs

示例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);
 }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:11,代码来源:EntityExtensions.cs

示例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.");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:21,代码来源:MiscellaneousExtensionsTests.cs

示例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.");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:15,代码来源:MiscellaneousExtensionsTests.cs

示例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");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:14,代码来源:MiscellaneousExtensionsTests.cs

示例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");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:9,代码来源:MiscellaneousExtensionsTests.cs


注:本文中的System.Collections.Specialized.NameValueCollection.ToDictionary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。