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


C# HashSet.Select方法代码示例

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


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

示例1: GetAppAssembliesAsync

        /// <summary>
        /// Gets the application assemblies.
        /// </summary>
        /// <param name="assemblyFilter">(Optional) A filter for the assemblies.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A promise of an enumeration of application assemblies.
        /// </returns>
        public virtual async Task<IEnumerable<Assembly>> GetAppAssembliesAsync(Func<AssemblyName, bool> assemblyFilter = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // TODO The assemblies from the current domain do not consider the not loaded
            // but required referenced assemblies. Therefore load all the references recursively.
            // This could be optimized somehow.
            var assemblies = this.GetLoadedAssemblies();

            assemblyFilter = assemblyFilter ?? this.AssemblyFilter;
            var loadedAssemblyRefs = new HashSet<string>(assemblies.Select(a => a.GetName().FullName));
            var assembliesToCheck = assemblies.Where(a => assemblyFilter(a.GetName())).ToList();

            while (assembliesToCheck.Count > 0)
            {
                var assemblyRefsToLoad = new HashSet<AssemblyName>();
                foreach (var assembly in assembliesToCheck)
                {
                    var referencesToLoad = this.GetReferencedAssemblies(assembly).Where(a => !loadedAssemblyRefs.Contains(a.FullName) && assemblyFilter(a));
                    assemblyRefsToLoad.AddRange(referencesToLoad);
                }

                loadedAssemblyRefs.AddRange(assemblyRefsToLoad.Select(an => an.FullName));
                assembliesToCheck = assemblyRefsToLoad.Select(this.AssemblyLoader.LoadAssembly).ToList();
                assemblies.AddRange(assembliesToCheck);
            }

            await this.AddAdditionalAssembliesAsync(assemblies, assemblyFilter, cancellationToken).PreserveThreadContext();
            return assemblies;
        }
开发者ID:raimu,项目名称:kephas,代码行数:36,代码来源:AppRuntimeBase.cs

示例2: SomeFunction

 public static void SomeFunction()
 {
     Dictionary<int, int> dict = new Dictionary<int, int>();
     dict.Add(4, 3);
     Console.WriteLine(dict[4]);
     Console.WriteLine(dict.ContainsKey(8));
     dict.Remove(4);
     foreach(int key in dict.Keys)
         Console.WriteLine(key);
     foreach(int val in dict.Values)
         Console.WriteLine(val);
     foreach(var kv in dict)
         Console.WriteLine(kv.Key + " " + kv.Value);
     var dict2 = dict.ToDictionary(o => o.Key, o => o.Value);
     var vals = dict.Values;
     
     HashSet<int> hash = new HashSet<int>();
     hash.Add(999);
     Console.WriteLine(hash.Contains(999));
     hash.Remove(999);
     Console.WriteLine(hash.Contains(999));
     foreach(int hashItem in hash)
         Console.WriteLine(hashItem);
     var z = hash.Select(o => 3).ToArray();
     var g = hash.GroupBy(o => o).Select(o => o.Count()).Min();
 }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:26,代码来源:DictionaryAndHashSet.cs

示例3: CreateUserIdentity

        public static ClaimsIdentity CreateUserIdentity(string emailAddress, string id, string[] organizationIds, string[] roles, string defaultProjectId = null) {
            var claims = new List<Claim> {
                    new Claim(ClaimTypes.Name, emailAddress),
                    new Claim(ClaimTypes.NameIdentifier, id),
                    new Claim(OrganizationIdsClaim, String.Join(",", organizationIds))
                };

            if (!String.IsNullOrEmpty(defaultProjectId))
                claims.Add(new Claim(DefaultProjectIdClaim, defaultProjectId));

            var userRoles = new HashSet<string>(roles);
            if (userRoles.Any()) {
                // add implied scopes
                if (userRoles.Contains(AuthorizationRoles.GlobalAdmin))
                    userRoles.Add(AuthorizationRoles.User);

                if (userRoles.Contains(AuthorizationRoles.User))
                    userRoles.Add(AuthorizationRoles.Client);

                claims.AddRange(userRoles.Select(scope => new Claim(ClaimTypes.Role, scope)));
            } else {
                claims.Add(new Claim(ClaimTypes.Role, AuthorizationRoles.Client));
                claims.Add(new Claim(ClaimTypes.Role, AuthorizationRoles.User));
            }

            return new ClaimsIdentity(claims, UserAuthenticationType);
        }
开发者ID:aamarber,项目名称:Exceptionless,代码行数:27,代码来源:IdentityUtils.cs

示例4: GetRecursiveDependentsAsync

        ///<summary>Gets all files that indirectly depend on the specified file.</summary>
        public async Task<IEnumerable<string>> GetRecursiveDependentsAsync(string fileName)
        {
            HashSet<GraphNode> visited;
            fileName = Path.GetFullPath(fileName);
            using (await rwLock.ReadLockAsync())
            {
                GraphNode rootNode;
                if (!nodes.TryGetValue(fileName, out rootNode))
                    return Enumerable.Empty<string>();

                var stack = new Stack<GraphNode>();
                stack.Push(rootNode);
                visited = new HashSet<GraphNode> { rootNode };
                while (stack.Count > 0)
                {
                    foreach (var child in stack.Pop().Dependents)
                    {
                        if (!visited.Add(child)) continue;
                        stack.Push(child);
                    }
                }
                // Don't return the original file.
                visited.Remove(rootNode);
            }
            return visited.Select(n => n.FileName);
        }
开发者ID:kodybrown,项目名称:WebEssentials2013,代码行数:27,代码来源:DependencyGraph.cs

示例5: Circulars

        public static int Circulars(int range)
        {
            int count = 0;
            HashSet<int> primes = new HashSet<int>();
            primes.UnionWith(Primes.primeRange(range));
            HashSet<string> stringprimes = new HashSet<string>();
            stringprimes.UnionWith(primes.Select<int, string>(x => x.ToString()));

            stringprimes.RemoveWhere(x => x.Contains('2') || x.Contains('4') || x.Contains('6') || x.Contains('8') || x.Contains('0'));

            foreach (string number in stringprimes) {
                string varnumber = number.Substring(0);
                bool allPrime = true;
                for (int i = 0; i < number.Length; i++) {
                    char c = varnumber.First<char>();
                    varnumber += c;
                    varnumber = varnumber.Remove(0, 1);
                    if (!primes.Contains(int.Parse(varnumber))) {
                        //Console.WriteLine(number);
                        allPrime = false;
                        break;
                    }
                }
                if (allPrime == true) {
                    count++;
                }
                allPrime = true;
            }
            return count + 1;
        }
开发者ID:MadRubicant,项目名称:Project-Euler,代码行数:30,代码来源:CircularPrimes.cs

示例6: Main

        private static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            string[] k = new string[t];
            for (int i = 0; i < k.Length; i++)
            {
                k[i] = Console.ReadLine();
            }

            string temp = @"<[ ]{0,}[a-z]{1,}[\d]{0,}";
            var regex = new Regex(temp);
            HashSet<string> rez = new HashSet<string>();
            for (int i = 0; i < k.Length; i++)
            {
                var matchs = regex.Matches(k[i]);
                foreach (var r in matchs)
                {
                    var match = (Match)r;

                        rez.Add(match.Value);

                }
            }
            var s = rez
                .Select(f=>f.Substring(1))
                .ToArray();
            Array.Sort(s);
            string mimimi = string.Join(";", s);

            Console.Write(mimimi);
        }
开发者ID:Elta20042004,项目名称:Training,代码行数:31,代码来源:Program.cs

示例7: AddNamespaceImports

        private SyntaxNode AddNamespaceImports(
            Document document,
            SemanticModel model,
            OptionSet options,
            IEnumerable<INamespaceSymbol> namespaces)
        {
            var existingNamespaces = new HashSet<INamespaceSymbol>();
            this.GetExistingImportedNamespaces(document, model, existingNamespaces);

            var namespacesToAdd = new HashSet<INamespaceSymbol>(namespaces);
            namespacesToAdd.RemoveAll(existingNamespaces);

            var root = model.SyntaxTree.GetRoot();
            if (namespacesToAdd.Count == 0)
            {
                return root;
            }

            var gen = SyntaxGenerator.GetGenerator(document);

            var newRoot = root;
            foreach (var import in namespacesToAdd.Select(ns => gen.NamespaceImportDeclaration(ns.ToDisplayString()).WithAdditionalAnnotations(Simplifier.Annotation)))
            {
                newRoot = this.InsertNamespaceImport(newRoot, gen, import, options);
            }

            return newRoot;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:28,代码来源:ImportAdderService.cs

示例8: Install

        public void Install(RunningDeployment deployment)
        {
            var transformDefinitions = GetTransformDefinitions(deployment.Variables.Get(SpecialVariables.Package.AdditionalXmlConfigurationTransforms));

            var sourceExtensions = new HashSet<string>(
                  transformDefinitions
                    .Where(transform => transform.Advanced)
                    .Select(transform => "*" + Path.GetExtension(transform.SourcePattern))
                    .Distinct()
                );

            if (deployment.Variables.GetFlag(SpecialVariables.Package.AutomaticallyRunConfigurationTransformationFiles))
            {
                sourceExtensions.Add("*.config");
                transformDefinitions.Add(new XmlConfigTransformDefinition("Release"));

                var environment = deployment.Variables.Get(SpecialVariables.Environment.Name);
                if (!string.IsNullOrWhiteSpace(environment))
                {
                    transformDefinitions.Add(new XmlConfigTransformDefinition(environment));
                }
            }

            var transformsRun = new HashSet<Tuple<string, string>>();
            foreach (var configFile in fileSystem.EnumerateFilesRecursively(deployment.CurrentDirectory, sourceExtensions.ToArray()))
            {
                ApplyTransformations(configFile, transformDefinitions, transformsRun);
            }

            deployment.Variables.SetStrings(SpecialVariables.AppliedXmlConfigTransforms, transformsRun.Select(t => t.Item1), "|");
        }
开发者ID:jinhong-,项目名称:Calamari,代码行数:31,代码来源:ConfigurationTransformsConvention.cs

示例9: GetBindingRedirects

        /// <summary>
        /// Returns a list of assemblies that need binding redirects.
        /// </summary>
        /// <param name="assemblies">List assemblies to analyze for binding redirects</param>
        public static IEnumerable<AssemblyBinding> GetBindingRedirects(IEnumerable<IAssembly> assemblies)
        {
            if (assemblies == null) {
                throw new ArgumentNullException("assemblies");
            }

            // Evaluate the list eagerly
            var assemblyList = assemblies.ToList();

            var assemblyNameLookup = assemblyList.ToDictionary(GetUniqueKey);

            // Output set of assemblies we need redirects for
            var redirectAssemblies = new HashSet<IAssembly>();

            // For each available assembly
            foreach (IAssembly assembly in assemblyList) {
                foreach (IAssembly referenceAssembly in assembly.ReferencedAssemblies) {
                    Tuple<string, string> key = GetUniqueKey(referenceAssembly);
                    IAssembly targetAssembly;
                    // If we have an assembly with the same unique key in our list of a different version then we want to use that version
                    // then we want to add a redirect for that assembly
                    if (assemblyNameLookup.TryGetValue(key, out targetAssembly) && targetAssembly.Version != referenceAssembly.Version) {
                        redirectAssemblies.Add(targetAssembly);
                    }
                }
            }

            return redirectAssemblies.Select(a => new AssemblyBinding(a));
        }
开发者ID:jerriclynsjohn,项目名称:nuget,代码行数:33,代码来源:BindingRedirectResolver.cs

示例10: AddNamespaceImportsAsync

        private async Task<SyntaxNode> AddNamespaceImportsAsync(
            Document document,
            SemanticModel model,
            OptionSet options,
            IEnumerable<INamespaceSymbol> namespaces,
            CancellationToken cancellationToken)
        {
            var existingNamespaces = new HashSet<INamespaceSymbol>();
            await this.GetExistingImportedNamespacesAsync(document, model, existingNamespaces, cancellationToken).ConfigureAwait(false);

            var namespacesToAdd = new HashSet<INamespaceSymbol>(namespaces);
            namespacesToAdd.RemoveAll(existingNamespaces);

            var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
            if (namespacesToAdd.Count == 0)
            {
                return root;
            }

            var gen = SyntaxGenerator.GetGenerator(document);

            var newRoot = root;
            foreach (var import in namespacesToAdd.Select(ns => gen.NamespaceImportDeclaration(ns.ToDisplayString()).WithAdditionalAnnotations(Simplifier.Annotation)))
            {
                newRoot = this.InsertNamespaceImport(newRoot, gen, import, options);
            }

            return newRoot;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:29,代码来源:ImportAdderService.cs

示例11: Get

 public ReplayViewModel Get([FromUri]string[] ids)
 {
     var heads = new[]
     {
         new Directed {X = 1, Y = 13, Direction = Direction.East},
         new Directed {X = 25, Y = 13, Direction = Direction.West},
         new Directed {X = 13, Y = 1, Direction = Direction.North},
         new Directed {X = 13, Y = 25, Direction = Direction.South}
     };
     var n = 0;
     var unique = new HashSet<string>(ids);
     var fighters = unique
         .Select(id => snakeStore.GetById(id))
         .Where(s => s != null)
         .Take(4)
         .Select(snake => new Fighter(snake.Id, snake.Chips, heads[n++]))
         .ToList();
     var tickCount = Environment.TickCount;
     var replay = new Replay(tickCount) { BattleField = new BattleField() };
     if (fighters.Count > 0)
     {
         var battleField = new BattleField();
         var battleManager = new BattleManager(fighters, replay, new FieldComparer(battleField), battleField, tickCount);
         battleManager.Fight(550); //original 550    
     }
     var model = Mapper.Map<Replay, ReplayViewModel>(replay);
     return model;
 }
开发者ID:FoC-,项目名称:SnakeBattle.Net,代码行数:28,代码来源:BattleController.cs

示例12: MatchIndex

        public void MatchIndex()
        {
            string tournamentName = "ChallongeNet" + Utilities.RandomName();
            Debug.WriteLine(string.Format("Initializing with name {0}", tournamentName));

            var tournamentUnderTest = this.target.TournamentCreate(tournamentName, TournamentType.SingleElimination, tournamentName);

            var participantNames = new HashSet<string>();
            const int NumberOfParticipants = 8;
            while (participantNames.Count < NumberOfParticipants)
            {
                string name = "ChallongeNet" + Utilities.RandomName();
                participantNames.Add(name);
            }

            var participants = participantNames.Select(name => this.target.ParticipantCreate(tournamentUnderTest, new ParticipantCreateParameters { Name = name })).ToList();

            tournamentUnderTest = this.target.TournamentStart(tournamentUnderTest);

            var participant = participants.First();
            var parameters = new MatchIndexParameters { ParticipantId = participant.Id };
            var matches = this.target.MatchIndex(tournamentUnderTest, parameters);
            var m = matches.Where(match => match.Player1Id == participant.Id || match.Player2Id == participant.Id);
            Assert.AreEqual(1, m.Count());

            parameters = new MatchIndexParameters { State = MatchIndexParameters.MatchIndexState.complete };
            matches = this.target.MatchIndex(tournamentUnderTest, parameters);
            Assert.AreEqual(0, matches.Count);

            this.target.TournamentDestroy(tournamentUnderTest);
        }
开发者ID:PedersenThomas,项目名称:ChallongeNet,代码行数:31,代码来源:MatchTest.cs

示例13: RelatedEvents

        /// <summary>
        /// Retrieves all events across all aggregates that are related to the specified aggregate ids, in the order in which they were recorded.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="relatedToAggregateIds">The aggregate ids to which the events relate.</param>
        public static async Task<IEnumerable<StorableEvent>> RelatedEvents(
            this IQueryable<StorableEvent> events,
            params Guid[] relatedToAggregateIds)
        {
            var ids = new HashSet<Guid>(relatedToAggregateIds);

            var relatedEvents = new HashSet<StorableEvent>();

            int currentCount;

            do
            {
                currentCount = relatedEvents.Count;

                var unqueriedIds = ids.Where(id => ! relatedEvents.Select(e => e.AggregateId).Contains(id));

                var newEvents = await events.Where(e => unqueriedIds.Any(id => id == e.AggregateId)).ToArrayAsync();

                relatedEvents.UnionWith(newEvents);

                var moreIds = newEvents
                    .SelectMany(e => e.Body.ExtractGuids())
                    .Distinct()
                    .ToArray();

                if (!moreIds.Any())
                {
                    break;
                }

                ids.UnionWith(moreIds);
            } while (currentCount != relatedEvents.Count);

            return relatedEvents.OrderBy(e => e.Id);
        }
开发者ID:halakaraki,项目名称:Its.Cqrs,代码行数:40,代码来源:QueryableExtensions.cs

示例14: GatherFiles

        /// <summary> Converts a console file args into actual files. </summary>
        /// <remarks> Sequences like "test.vsdx *.vsdx .\test.vsdx" will be correctly recognized,
        /// no file duplicates will be created. </remarks>
        /// <param name="passedFileArgs">File arguments in the console input.</param>
        /// <returns>Sequence of files recognized in the console input.</returns>
        public static IEnumerable<FileInfo> GatherFiles(IList<string> passedFileArgs)
        {
            // Expand passed console input with possible wildcards and duplications into real unique file names:
            var expandedPaths = new HashSet<string>();
            foreach (var inputItem in passedFileArgs) {
                if (string.IsNullOrWhiteSpace(inputItem)) { continue; }

                string[] files;
                if (Directory.Exists(inputItem)) {
                    files = GetFiles(inputItem);
                } else {
                    string path = Path.GetDirectoryName(inputItem);
                    string filename = Path.GetFileName(inputItem);
                    if (filename == "*") {
                        filename = "*.*";
                    }

                    files = GetFiles(path, filename);
                }

                foreach (var file in files) {
                    expandedPaths.Add(file);
                }
            }
            // Expanded file names can be safely turned into FileInfos, since GetFiles()
            // only return real files which can be accessed.
            return expandedPaths.Select(expandedPath => new FileInfo(expandedPath));
        }
开发者ID:EnoughTea,项目名称:vipare,代码行数:33,代码来源:PathTools.cs

示例15: ToIdentity

        public static ClaimsIdentity ToIdentity(this User user, string defaultProjectId = null) {
            if (user == null)
                return WindowsIdentity.GetAnonymous();
            
            var claims = new List<Claim> {
                    new Claim(ClaimTypes.Name, user.EmailAddress),
                    new Claim(ClaimTypes.NameIdentifier, user.Id),
                    new Claim(OrganizationIdsClaim, String.Join(",", user.OrganizationIds.ToArray()))
                };

            if (!String.IsNullOrEmpty(defaultProjectId))
                claims.Add(new Claim(DefaultProjectIdClaim, defaultProjectId));

            var userRoles = new HashSet<string>(user.Roles.ToArray());
            if (userRoles.Any()) {
                // add implied scopes
                if (userRoles.Contains(AuthorizationRoles.GlobalAdmin))
                    userRoles.Add(AuthorizationRoles.User);

                if (userRoles.Contains(AuthorizationRoles.User))
                    userRoles.Add(AuthorizationRoles.Client);

                claims.AddRange(userRoles.Select(scope => new Claim(ClaimTypes.Role, scope)));
            } else {
                claims.Add(new Claim(ClaimTypes.Role, AuthorizationRoles.Client));
                claims.Add(new Claim(ClaimTypes.Role, AuthorizationRoles.User));
            }

            return new ClaimsIdentity(claims, UserAuthenticationType);
        }
开发者ID:Nangal,项目名称:Exceptionless,代码行数:30,代码来源:IdentityUtils.cs


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