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


C# ConcurrentDictionary.ForEach方法代码示例

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


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

示例1: InitializeFunctions

		private static void InitializeFunctions()
		{
			// public static methods only
			var methods = typeof(Methods).GetMethods(BindingFlags.Static | BindingFlags.Public);

			var funcs = new ConcurrentDictionary<string, ConcurrentBag<UberScriptFunction>>();

			Parallel.ForEach(
				methods,
				m =>
				{
					var p = m.GetParameters();

					// Always expect first parameter to be a trigger object.
					// Skip methods where names don't match rules: uppercase, optional digit, optional _
					if (p.Length == 0 || !p[0].ParameterType.IsEqual<TriggerObject>() ||
						!m.Name.All(n => Char.IsUpper(n) || Char.IsDigit(n) || n == '_'))
					{
						return;
					}

					var usf = new UberScriptFunction(m);

					funcs.AddOrUpdate(
						m.Name,
						s => new ConcurrentBag<UberScriptFunction>
						{
							usf
						},
						(s, l) =>
						{
							l.Add(usf);
							return l;
						});
				});

			Functions.Clear();

			int count = 0, overloaded = 0;

			funcs.ForEach(
				(k, l) =>
				{
					var v = l.ToArray();

					if (v.Length == 0)
					{
						return;
					}

					++count;
					overloaded += v.Length - 1;

					//Console.WriteLine("[UberScript]: {0}({1})", k, v.Length);

					Functions.Add(k, v);
				});

			Console.WriteLine("[UberScript]: Initialized {0} functions and {1} overloads!", count, overloaded);
		}
开发者ID:greeduomacro,项目名称:UO-Forever,代码行数:60,代码来源:UberScriptFunctions.cs

示例2: ShowModificationImportWindowDialog

        public void ShowModificationImportWindowDialog(string modificationPath)
        {
            var rootNodeViewModel = modificationImportViewModelFactory.FromDirectory(modificationPath);
             var solution = riotSolutionLoader.Load(@"V:\Riot Games\League of Legends\RADS", RiotProjectType.AirClient | RiotProjectType.GameClient);
             var airResolver = new Resolver(solution.ProjectsByType[RiotProjectType.AirClient].ReleaseManifest.Root);
             var gameResolver = new Resolver(solution.ProjectsByType[RiotProjectType.GameClient].ReleaseManifest.Root);

             var fileNodes = rootNodeViewModel.EnumerateFileNodes().ToArray();
             var importWindow = new ModificationImportWindow();
             var modificationImportViewModel = new ModificationImportViewModel(this, importWindow, rootNodeViewModel);
             modificationImportViewModel.ModificationFriendlyName = fileSystemProxy.GetDirectoryInfo(modificationPath).Name;
             importWindow.DataContext = modificationImportViewModel;
             new Thread(() => {
            foreach (var fileNode in fileNodes) {
               var path = fileNode.Path;
               var airResolution = airResolver.Resolve(path);
               if (airResolution.Any()) {
                  fileNode.ResolutionPath = airResolution.First().GetPath();
                  fileNode.ResolutionState = ResolutionState.ResolutionSuccessful;
               } else {
                  var gameResolutions = gameResolver.Resolve(path);
                  if (gameResolutions.Any()) {
                     fileNode.ResolutionPath = gameResolutions.First().GetPath();
                     fileNode.ResolutionState = ResolutionState.ResolutionSuccessful;
                  } else {
                     fileNode.ResolutionState = ResolutionState.ResolutionFailed;
                  }
               }
            }

            LeagueModificationCategory modificationType = LeagueModificationCategory.Other;
            if (fileNodes.Any(node => node.ResolutionState == ResolutionState.ResolutionSuccessful)) {
               var modificationTypeCounts = new ConcurrentDictionary<LeagueModificationCategory, int>();
               foreach (var file in fileNodes) {
                  if (file.ResolutionState == ResolutionState.ResolutionSuccessful) {
                     if (file.ResolutionPath.IndexOf("DATA/Characters", StringComparison.OrdinalIgnoreCase) != -1 ||
                         file.ResolutionPath.IndexOf("assets/images/champions", StringComparison.OrdinalIgnoreCase) != -1) {
                        if (file.ResolutionPath.IndexOf("ward", StringComparison.OrdinalIgnoreCase) != -1) {
                           modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Ward, 1, (existing, count) => count + 1);
                        } else {
                           modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Champion, 1, (existing, count) => count + 1);
                        }
                     } else if (file.ResolutionPath.IndexOf("LEVELS") != -1) {
                        modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Map, 1, (existing, count) => count + 1);
                     } else if (file.ResolutionPath.IndexOf("Menu", StringComparison.OrdinalIgnoreCase) != -1) {
                        modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.UserInterface, 1, (existing, count) => count + 1);
                     } else {
                        modificationTypeCounts.AddOrUpdate(LeagueModificationCategory.Other, 1, (existing, count) => count + 1);
                     }
                  }
               }
               var categorizationCounts = modificationTypeCounts.Sum(x => x.Value);
               var highestCategorization = modificationTypeCounts.MaxBy(key => key.Value, Comparer<int>.Default);
               if (highestCategorization.Value >= categorizationCounts * 2.0 / 3.0) {
                  modificationType = modificationTypeCounts.MaxBy(key => key.Value, Comparer<int>.Default).Key;
               }
               Console.WriteLine("Highest categorization: " + highestCategorization.Key.Name);
               modificationTypeCounts.ForEach(x => Console.WriteLine(x.Key.Name + ": " + x.Value));
               Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => {
                  modificationImportViewModel.ModificationCategorization = modificationType;
               }));
            }
             }).Start();
             importWindow.ShowDialog();
        }
开发者ID:ItzWarty,项目名称:the-dargon-project,代码行数:65,代码来源:ModificationImportController.cs


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