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


C# Dictionary.All方法代码示例

本文整理汇总了C#中Dictionary.All方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.All方法的具体用法?C# Dictionary.All怎么用?C# Dictionary.All使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dictionary的用法示例。


在下文中一共展示了Dictionary.All方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateBusinessLogic

        /// <summary>
        /// Apply business logic here
        /// </summary>
        /// <param name="productsToImport"></param>
        /// <returns></returns>
        public Dictionary<string, List<string>> ValidateBusinessLogic(IEnumerable<ProductImportDataTransferObject> productsToImport)
        {
            var errors = new Dictionary<string, List<string>>();
            var productRules = MrCMSApplication.GetAll<IProductImportValidationRule>();
            var productVariantRules = MrCMSApplication.GetAll<IProductVariantImportValidationRule>();

            foreach (var product in productsToImport)
            {
                var productErrors = productRules.SelectMany(rule => rule.GetErrors(product)).ToList();
                if (productErrors.Any())
                    errors.Add(product.UrlSegment, productErrors);

                foreach (var variant in product.ProductVariants)
                {
                    var productVariantErrors = productVariantRules.SelectMany(rule => rule.GetErrors(variant)).ToList();
                    if (productVariantErrors.Any())
                    {
                        if (errors.All(x => x.Key != product.UrlSegment))
                            errors.Add(product.UrlSegment, productVariantErrors);
                        else
                            errors[product.UrlSegment].AddRange(productVariantErrors);
                    }

                }
            }

            return errors;
        }
开发者ID:neozhu,项目名称:Ecommerce,代码行数:33,代码来源:ImportProductsValidationService.cs

示例2: DetermineMissingServices

		public static List<IRequiredService> DetermineMissingServices(this IEnumerable<XmlModuleConfig> modules, List<string> bootStrappedServices)
		{
			var providedServices = new List<IProvidedService>();
			var requiredServices = new Dictionary<IRequiredService, XmlModuleConfig>();

			foreach (var module in modules)
			{
				foreach (IRequiredService requiredService in module.RequiredServices)
				{
					if (requiredServices.All(r => r.Key.ServiceName != requiredService.ServiceName))
					{
						requiredServices.Add(requiredService, module);
					}
				}

				foreach (IProvidedService providedService in module.ProvidedServices)
				{
					if (providedServices.All(r => r.ServiceName != providedService.ServiceName))
					{
						providedServices.Add(providedService);
					}
				}
			}

			var query =
				requiredServices.Where(
					requiredService =>
					providedServices.All(s => s.ServiceName != requiredService.Key.ServiceName)
					&& bootStrappedServices.All(s => s != requiredService.Key.ServiceName));

			return query.Select(s => s.Key).ToList();
		}
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:32,代码来源:ModuleConfigEnumerableExtensions.cs

示例3: CalculateMode

        public string CalculateMode(List<decimal> numbers)
        {
            decimal max = 0;
            string result = "";

            var numDictionary = new Dictionary<decimal, int>();

            AddToDictionary(numbers, numDictionary);

            if(numDictionary.Count == 0)
                throw new ArgumentException("No numbers given!", "numbers");

            if (numDictionary.All(d => d.Value == 1))
                return "none";

            foreach (KeyValuePair<decimal, int> pair in numDictionary)
            {
                if (pair.Value > max)
                {
                    result = "";
                    max = pair.Value;
                    result += string.Format("{0},", pair.Key);
                }

                else if (pair.Value == max)
                    result += string.Format("{0},", pair.Key);

            }

            return result.Trim(',');
        }
开发者ID:ronb1982,项目名称:Portfolio,代码行数:31,代码来源:ModeCalculator.cs

示例4: DetermineIfAnagram

        public bool DetermineIfAnagram(string s1, string s2)
        {
            if (s1.Length != s2.Length)
            {
                return false;
            }

            var dict = new Dictionary<char,int>();

            foreach (var item in s1)
            {
                if (dict.ContainsKey(item))
                {
                    dict[item]++;
                }
                else
                {
                    dict.Add(item, 1);
                }
            }

            foreach (var item in s2)
            {
                if (!dict.ContainsKey(item))
                {
                    return false;
                }
                else
                {
                    dict[item]--;
                }
            }

            return dict.All(x => x.Value == 0);
        }
开发者ID:joshuayg,项目名称:QQCode,代码行数:35,代码来源:StringQuestions.cs

示例5: Test_Gamma_Of_Valid_Values

        public void Test_Gamma_Of_Valid_Values()
        {
            Dictionary<double, double> expected = new Dictionary<double, double> {
                {1,1},
                {Math.PI, 2.288037796},
                {Math.E, 1.567468255},
                {-1.5,2.363271801}
            };

            //foreach (var item in expected)
            //{
            //    double actual = GammaRelated.Gamma(item.Key);
            //    Assert.IsTrue(AreApproximatelyEqual(item.Value, actual));
            //}

            Assert.IsTrue(
                expected.All(x =>
                    AreApproximatelyEqual(x.Value, GammaRelated.Gamma(x.Key))
                    )
                    );

            Assert.IsTrue(
                AreApproximatelyEqual(
                GammaRelated.Gamma(Math.PI + 1),
                Math.PI * GammaRelated.Gamma(Math.PI)
                )
                );
        }
开发者ID:rodriada000,项目名称:Mathos-Project,代码行数:28,代码来源:GammaTests.cs

示例6: DictionaryExtensions_All_ReturnsTrueIfDictionaryIsEmpty

        public void DictionaryExtensions_All_ReturnsTrueIfDictionaryIsEmpty()
        {
            var dictionary = new Dictionary<Int32, String>();

            var result = dictionary.All(x => x.Key % 2 == 0);

            TheResultingValue(result).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:8,代码来源:DictionaryExtensionsTest.cs

示例7: WebConfigStateAllowsEnumeratingOverConfigItems

        public void WebConfigStateAllowsEnumeratingOverConfigItems() {
            // Arrange
            var dictionary = new Dictionary<string, string> { { "a", "b" }, { "c", "d" }, { "x12", "y34" } };
            var stateStorage = GetWebConfigScopeStorage(dictionary);

            // Act and Assert
            Assert.IsTrue(dictionary.All(item => item.Value == stateStorage[item.Key] as string));
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:8,代码来源:WebConfigScopeStorageTest.cs

示例8: AddStream

 public bool AddStream(string sStreamName)
 {
     var results = new Dictionary<IStreamProvider, bool>();
     foreach (var streamProvider in _streamProviders)
     {
         results.Add(streamProvider, streamProvider.AddStream(sStreamName));
     }
     return results.All(result => !result.Value);
 }
开发者ID:Kolpa,项目名称:DeathmicChatbot,代码行数:9,代码来源:StreamProviderManager.cs

示例9: CountWords_EmptySentences_CountsWordCorrectly

        public void CountWords_EmptySentences_CountsWordCorrectly()
        {
            var wordsCounter = new ClassicCounterLogic();
            var properDict = new Dictionary<string, int>();

            var result = wordsCounter.CountWordsInSentence(string.Empty);

            Assert.IsTrue(properDict.All(e => result.Contains(e)));
        }
开发者ID:mich4lk,项目名称:EpamWordCounter,代码行数:9,代码来源:ClassicCounterLogicTest.cs

示例10: DispatchCommand

 internal static int DispatchCommand(Dictionary<CommandMetadata, object> commands, string[] args)
 {
     if (args == null || !args.Any()) throw new ShellHelpException();
     var commandName = args.First().ToLower();
     if (commands.All(meta => meta.Key.Name != commandName)) throw new ShellHelpException();
     var command = commands.Single(meta => meta.Key.Name == commandName).Value;
     var metadata = commands.Single(meta => meta.Key.Name == commandName).Key;
     return RunCommand(command, metadata, args.Skip(1).ToArray());
 }
开发者ID:satejnik,项目名称:commandshell,代码行数:9,代码来源:CommandDispatcher.cs

示例11: SearchEngine

        public SearchEngine(Dictionary<string, List<string>> lookups)
        {
            if (lookups == null)
                throw new ArgumentNullException("lookups");
            if (lookups.Count == 0)
                throw new ArgumentException("The lookups must not be empty.", "lookups");
            if (lookups.All(x => x.Value.Count == 0))
                throw new ArgumentException("None of the lookups (keys) have results (values). This is invalid as a lookup table.");

            _lookupTable = lookups;
        }
开发者ID:cohen990,项目名称:station-search-algorithm,代码行数:11,代码来源:SearchEngine.cs

示例12: GetAllKeysAsListTestCase

        public void GetAllKeysAsListTestCase()
        {
            var dictionary = new Dictionary<String, String>
            {
                { RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() },
                { RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() }
            };

            var allKeys = dictionary.GetAllKeysAsList();
            Assert.IsTrue( dictionary.All( x => allKeys.Contains( x.Key ) ) );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:11,代码来源:IDictionary[K,+V].GetAllKeysAsList.Test.cs

示例13: TestPostRequestWithCustomeHeadersAndBody

        public async Task TestPostRequestWithCustomeHeadersAndBody()
        {
            using (var server = new HttpHost(TestPort))
            {
                const string path = "/test/path?query=value";
                var headers = new Dictionary<string, string>
                    { { "custom-header-1", "custom-value-1" }, { "content-custom", "content-value" } };
                const string contentType = "suave/test";
                const string content = "string content";
                var responseContent = new byte[] { 1, 2, 3 };

                await server.OpenAsync(async request =>
                {
                    Assert.Equal(path, request.RequestUri.PathAndQuery);

                    Assert.Equal(HttpMethod.Post, request.Method);

                    Assert.True(headers.All(pair => request.Headers.First(s => s.Key == pair.Key).Value.First() == pair.Value));

                    Assert.Equal(contentType, request.Content.Headers.ContentType.ToString());

                    Assert.Equal(content, await request.Content.ReadAsStringAsync());

                    var response =  new HttpResponseMessage
                    {
                        StatusCode = HttpStatusCode.Accepted,
                        Content = new ByteArrayContent(responseContent)
                    };
                    response.Headers.Add("server-custom", "server-value");
                    return response;
                });

                using (var client = new HttpClient())
                {
                    var request = new HttpRequestMessage(HttpMethod.Post, LocalHost + path);
                    headers.Aggregate(request.Headers, (a, b) =>
                    {
                        a.Add(b.Key, b.Value);
                        return a;
                    });
                    request.Content = new StringContent(content);
                    request.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

                    var response = await client.SendAsync(request);
                    
                    Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);

                    Assert.Equal(responseContent, await response.Content.ReadAsByteArrayAsync());

                    Assert.Equal("server-value", response.Headers.First(s => s.Key == "server-custom").Value.First());
                }
            }
        }
开发者ID:ahmelsayed,项目名称:SuaveServerWrapper,代码行数:53,代码来源:HttpHostTests.cs

示例14: Authorize

        /// <summary>
        /// Adds authorization token to POST body
        /// </summary>
        /// <param name="body">Dictionary containing the body parameters</param>
        /// <param name="token">The token to add to the post body</param>
        /// <returns></returns>
        public virtual Dictionary<string, object> Authorize(Dictionary<string, object> body, string token)
        {
            if (body == null)
                throw new ArgumentNullException("body");

            var d = new Dictionary<string, object>(body);

            if (d.All(b => !String.Equals(b.Key, this.FieldName, StringComparison.CurrentCultureIgnoreCase)))
                d.Add(this.FieldName, token);

            return d;
        }
开发者ID:krackjax,项目名称:Coinbase.NET,代码行数:18,代码来源:AuthenticatorBase.cs

示例15: DictionaryExtensions_All_ReturnsTrueIfAllItemsMatchPredicate

        public void DictionaryExtensions_All_ReturnsTrueIfAllItemsMatchPredicate()
        {
            var dictionary = new Dictionary<Int32, String>()
            {
                { 2, "A" },
                { 4, "B" },
                { 6, "C" },
            };

            var result = dictionary.All(x => x.Key % 2 == 0);

            TheResultingValue(result).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:13,代码来源:DictionaryExtensionsTest.cs


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