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


C# List.ToLookup方法代码示例

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


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

示例1: HtmlCreator

 public HtmlCreator(string text, List<Marker> markers)
 {
     this.text = text;
     this.markers = markers;
     if (markers.Any(m => m.LInclusive < 0 || m.RExclusive > text.Length))
         throw new ArgumentException();
     open = markers.ToLookup(g => g.LInclusive);
     close = markers.ToLookup(g => g.RExclusive);
     result = new StringBuilder();
     Create();
 }
开发者ID:mpivko,项目名称:01-quality,代码行数:11,代码来源:HtmlCreator.cs

示例2: OnSerialize

        private void OnSerialize(StreamingContext context)
        {
            RepopulateHyperMedia();

            if (ResourceConverter.IsResourceConverterContext(context))
            {
                // put all embedded resources and lists of resources into Embedded for the _embedded serializer
                var resourceList = new List<IResource>();
                foreach (var prop in GetType().GetProperties().Where(p => IsEmbeddedResourceType(p.PropertyType)))
                {
                    var val = prop.GetValue(this, null);
                    if (val != null)
                    {
                        // remember embedded resource property for restoring after serialization
                        embeddedResourceProperties.Add(prop, val);
                        // add embedded resource to collection for the serializtion
                        var res = val as IResource;
                        if (res != null)
                            resourceList.Add(res);
                        else
                            resourceList.AddRange((IEnumerable<IResource>) val);
                        // null out the embedded property so it doesn't serialize separately as a property
                        prop.SetValue(this, null, null);
                    }
                }
                foreach (var res in resourceList.Where(r => string.IsNullOrEmpty(r.Rel)))
                    res.Rel = "unknownRel-" + res.GetType().Name;
                Embedded = resourceList.Count > 0 ? resourceList.ToLookup(r => r.Rel) : null;
            }
        }
开发者ID:JeroenSoeters,项目名称:WebApi.Hal,代码行数:30,代码来源:Representation.cs

示例3: createDict

 public static ILookup<string, float> createDict()
 {
     List<KeyValuePair<string, float>> list = new List<KeyValuePair<string, float>>();
     list.Add(new KeyValuePair<string, float>("", 10));
     var dict = list.ToLookup(kvp => kvp.Key, kvp => kvp.Value);
     return dict;
 }
开发者ID:dariukas,项目名称:Scanorama,代码行数:7,代码来源:Zodynas.cs

示例4: GetActionMapping

        public override ILookup<string, HttpActionDescriptor> GetActionMapping(HttpControllerDescriptor controllerDescriptor)
        {
            if(controllerDescriptor.ControllerType == typeof(SlimApiGhostController)) {
            var newActions = new List<HttpActionDescriptor>();
            foreach(var contrInfo in _apiConfig.ControllerInfos) {
              var methods = contrInfo.Type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
              foreach(var method in methods) {
            var dtype = method.DeclaringType;
            if (dtype == typeof(object)) //skip ToString()
              continue;
            var action = new SlimApiActionDescriptor(controllerDescriptor, method, contrInfo, _apiConfig);
            if (action.RouteTemplates.Count > 0 && action.SupportedHttpMethods.Count > 0) {
              RegisterAction(action);
              newActions.Add(action);

            }
              }
            } //foreach ct

            var lkp = newActions.ToLookup(a => a.ActionName, StringComparer.OrdinalIgnoreCase);
            return lkp;
              }
              // otherwise call base
              return base.GetActionMapping(controllerDescriptor);
        }
开发者ID:yuanfei05,项目名称:vita,代码行数:25,代码来源:SlimApiActionSelector.cs

示例5: Lookup

        private static void Lookup()
        {
            // Create a list of Packages to put into a Lookup data structure.
            List<Package> packages = new List<Package> { new Package { Company = "Coho Vineyard", Weight = 25.2, TrackingNumber = 89453312L },
                                                 new Package { Company = "Lucerne Publishing", Weight = 18.7, TrackingNumber = 89112755L },
                                                 new Package { Company = "Wingtip Toys", Weight = 6.0, TrackingNumber = 299456122L },
                                                 new Package { Company = "Contoso Pharmaceuticals", Weight = 9.3, TrackingNumber = 670053128L },
                                                 new Package { Company = "Wide World Importers", Weight = 33.8, TrackingNumber = 4665518773L } };

            // Create a Lookup to organize the packages. Use the first character of Company as the key value.
            // Select Company appended to TrackingNumber for each element value in the Lookup.

            // a look up vs igrouping is like a dictionary vs keyvaluepair
            // look up is collection, igrouping is the item it has key and ienumerable of things
            Lookup<char, string> lookup = (Lookup<char, string>)packages.ToLookup(p => Convert.ToChar(p.Company.Substring(0, 1)),
                p => p.Company + " " + p.TrackingNumber);

            foreach (IGrouping<char, string> packageGroup in lookup)
            {
                // Print the key value of the IGrouping.
                Console.WriteLine(packageGroup.Key);
                // Iterate through each value in the IGrouping and print its value.
                foreach (string str in packageGroup)
                    Console.WriteLine("    {0}", str);
            }
        }
开发者ID:cleancodenz,项目名称:LEDA,代码行数:26,代码来源:Program.cs

示例6: LoadEntries

        public void LoadEntries(DataFile file, IndexEntry indexEntry)
        {
            var list = new List<RootEntry>();
            var blteEntry = new BinaryReader(DataFile.LoadBLTEEntry(indexEntry, file.readStream));

            while (blteEntry.BaseStream.Position < blteEntry.BaseStream.Length)
            {
                var entries = new RootEntry[blteEntry.ReadInt32()];

                blteEntry.BaseStream.Position += 4;

                var locales = (Locales)blteEntry.ReadUInt32();

                blteEntry.BaseStream.Position += (entries.Length << 2);

                for (var i = 0; i < entries.Length; i++)
                {
                    list.Add(new RootEntry
                    {
                        MD5 = blteEntry.ReadBytes(16),
                        Hash = blteEntry.ReadUInt64(),
                        Locales = locales
                    });
                }
            }

            entries = list.ToLookup(re => re.Hash);
        }
开发者ID:icyblade,项目名称:arctium-tools,代码行数:28,代码来源:RootFile.cs

示例7: GetAllValuesFromSection

        /// <summary>
        /// This method will return all values from a given section in a dictionary
        /// </summary>
        /// <param name="section">The name of the section</param>
        /// <returns>A dictionary containing propertynames and values.</returns>
        public ILookup<int, string> GetAllValuesFromSection(string section)
        {
            string str;
            int name;
            string val;
            List<PrioritizedProcess> map = new List<PrioritizedProcess>();

            using (StreamReader reader = new StreamReader(_path))
            {
                while (!reader.EndOfStream)
                {
                    if ((str = reader.ReadLine()).Equals(@"[" + section + "]"))
                    {
                        while ((str = reader.ReadLine() ?? "").Contains("="))
                        {
                            if (!Int32.TryParse(str.Split('=')[0], out name))
                                continue;

                            val = str.Split('=')[1];

                            map.Add(new PrioritizedProcess() { Priority = name, Path = val });
                        }
                    }
                }
            }

            return map.ToLookup(p => p.Priority, p => p.Path);
        }
开发者ID:Borderloop,项目名称:Nutella,代码行数:33,代码来源:INIFile.cs

示例8: GetResetPasswordRuleSet

 public static RuleSet GetResetPasswordRuleSet()
 {
     var rules = new List<KeyValuePair<string, Rule>>
                     {
                         new KeyValuePair<string, Rule>("UserName", new RequiredRule{ ErrorMessage = "Bạn chưa nhập địa chỉ tên đăng nhập của bạn"})
                     };
     return new RuleSet(rules.ToLookup(k => k.Key, v => v.Value));
 }
开发者ID:preguntoncojonero,项目名称:mylifevn,代码行数:8,代码来源:Validates.cs

示例9: Remove

        private static void Remove(List<int> collection)
        {
            var listOfItemsToBeRemoved = collection
                                        .ToLookup(x => x)
                                        .Where(g => g.Count() % 2 != 0)
                                        .SelectMany(g => g);

            collection.RemoveAll(listOfItemsToBeRemoved.Contains);
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:9,代码来源:Program.cs

示例10: SendEmail

        /// <summary>
        /// 
        /// </summary>
        /// <param name="course"></param>
        /// <param name="user"></param>
        /// <returns>a lookup true = successfully emailed, false = email failed</returns>
        public static async Task<ILookup<bool, CourseParticipant>> SendEmail(Course course, IPrincipal user)
        {
            using (var cal = Appointment.CreateCourseAppointment(course, user.Identity))
            {
                using (var appt = new AppointmentStream(cal))
                {
                    var map = ((Expression<Func<CourseParticipant, CourseParticipantDto>>)new CourseParticipantMaps().MapToDto).Compile();
                    var faculty = course.CourseParticipants.Where(cp => !map(cp).IsEmailed)
                        .ToLookup(cp => cp.IsFaculty);

                    IEnumerable<Attachment> attachments = new Attachment[0];
                    using (var client = new SmtpClient())
                    {
                        var mailMessages = new List<ParticipantMail>();
                        var sendMail = new Action<CourseParticipant>(cp =>
                        {
                            var mail = new MailMessage();
                            mail.To.AddParticipants(cp.Participant);
                            var confirmEmail = new CourseInvite { CourseParticipant = cp };
                            mail.CreateHtmlBody(confirmEmail);
                            appt.AddAppointmentsTo(mail);
                            foreach (var a in attachments)
                            {
                                a.ContentStream.Position = 0;
                                mail.Attachments.Add(a);
                            }
                            mailMessages.Add(new ParticipantMail { Message = mail, SendTask = client.SendMailAsync(mail), CourseParticipant = cp });
                        });

                        foreach (var cp in faculty[false])
                        {
                            sendMail(cp);
                        }
                        if (faculty[true].Any())
                        {
                            if (course.FacultyMeetingUtc.HasValue)
                            {
                                using (var fm = Appointment.CreateFacultyCalendar(course))
                                {
                                    appt.Add(fm);
                                }
                            }
                            attachments = GetFilePaths(course).Select(fp => new Attachment(fp.Value, System.Net.Mime.MediaTypeNames.Application.Zip) { Name = fp.Key })
                                .Concat(new[] { new Attachment(CreateDocxTimetable.CreateTimetableDocx(course, WebApiConfig.DefaultTimetableTemplatePath), OpenXmlDocxExtensions.DocxMimeType) { Name = CreateDocxTimetable.TimetableName(course)} });
                            foreach (var cp in faculty[true])
                            {
                                sendMail(cp);
                            }
                        }
                        await Task.WhenAll(mailMessages.Select(mm => mm.SendTask));
                        mailMessages.ForEach(mm => mm.Message.Dispose());
                        return mailMessages.ToLookup(k => k.SendTask.Status == TaskStatus.RanToCompletion, v => v.CourseParticipant);
                    }
                }
            }
        }
开发者ID:mcshaz,项目名称:SimPlanner,代码行数:62,代码来源:CreateParticipantEmails.cs

示例11: GetContactRuleSet

 public static RuleSet GetContactRuleSet()
 {
     var rules = new List<KeyValuePair<string, Rule>>
                     {
                         new KeyValuePair<string, Rule>("Name", new RequiredRule{ ErrorMessage = "Bạn hãy nhập họ và tên của bạn"}),
                         new KeyValuePair<string, Rule>("Email", new RequiredRule{ ErrorMessage = "Bạn hãy nhập địa chỉ email của bạn"}),
                         new KeyValuePair<string, Rule>("Email", new RegularExpressionRule(Constants.Regulars.Email) {ErrorMessage = "Địa chỉ email của bạn không hợp lệ"}),
                         new KeyValuePair<string, Rule>("Content", new RequiredRule{ ErrorMessage = "Bạn hãy nhập nội dung phản hồi của bạn"}),
                     };
     return new RuleSet(rules.ToLookup(k => k.Key, v => v.Value));
 }
开发者ID:preguntoncojonero,项目名称:mylifevn,代码行数:11,代码来源:Validates.cs

示例12: GetEntityNames

        /// <summary>
        /// Get a list with schema entity names for its vocabularies. 
        /// Using vocabulary name rather than prefix from json, as the prefixes can be different in the view. 
        /// </summary>
        /// <remarks>
        /// Using <see cref="ILookup{TKey,TElement}"/> rather than a <see cref="Dictionary{TKey,TValue}"/> because it will allow for duplicate keys.
        /// Duplicate keys make no sense, but we might have them, so this prevents runtime exceptions.
        /// </remarks>
        /// <returns>List with entity names indexed by vocabulary</returns>
        public ILookup<string, string> GetEntityNames()
        {
            List<KeyValuePair<string, string>> entityNames = new List<KeyValuePair<string, string>>();
            foreach (SchemaSemantics schemaSemantics in Semantics)
            {
                string vocab = SemanticMapping.GetVocabulary(schemaSemantics.Prefix, Localization);
                entityNames.Add(new KeyValuePair<string, string>(vocab, schemaSemantics.Entity));
            }

            return entityNames.ToLookup(x => x.Key, x => x.Value);
        }
开发者ID:tgfl-tom,项目名称:dxa-web-application-dotnet,代码行数:20,代码来源:SemanticSchema.cs

示例13: GetChangePasswordRuleSet

 public static RuleSet GetChangePasswordRuleSet()
 {
     var rules = new List<KeyValuePair<string, Rule>>
                     {
                         new KeyValuePair<string, Rule>("OldPassword", new RequiredRule{ ErrorMessage = "Bạn chưa nhập mật khẩu cũ"}),
                         new KeyValuePair<string, Rule>("NewPassword", new RequiredRule{ ErrorMessage = "Bạn chưa nhập mật khẩu mới"}),
                         new KeyValuePair<string, Rule>("ConfirmNewPassword", new RequiredRule{ ErrorMessage = "Mật khẩu xác nhận không giống nhau"}),
                         new KeyValuePair<string, Rule>("ConfirmNewPassword", new ComparisonRule("NewPassword", ComparisonRule.Operator.Equals){ ErrorMessage = "Mật khẩu xác nhận không giống nhau"})
                     };
     return new RuleSet(rules.ToLookup(k => k.Key, v => v.Value));
 }
开发者ID:preguntoncojonero,项目名称:mylifevn,代码行数:11,代码来源:Validates.cs

示例14: Main

        static void Main(string[] args)
        {
            List<int> numbers = new List<int> { 4, 2, 2, 5, 2, 3, 2, 3, 1, 5, 2 };

            var elementsToRemove = numbers.ToLookup(x => x).Where(xs => xs.Count() % 2 != 0);
            foreach (var item in elementsToRemove)
            {
                numbers.RemoveAll(x => x == item.Key);
            }

            Console.WriteLine(string.Join(", ", numbers));
        }
开发者ID:damy90,项目名称:Telerik-all,代码行数:12,代码来源:Program.cs

示例15: Create

        public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable<string> currentSearchPaths)
        {
            var snapshot = new ProjectContextSnapshot();

            var allDependencyDiagnostics = new List<DiagnosticMessage>();
            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            var allExports = context.CreateExporter(configuration)
                                    .GetAllExports()
                                    .ToDictionary(export => export.Library.Identity.Name);

            var allSourceFiles = new List<string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences = new List<string>();
            var allProjectReferences = new List<ProjectReferenceDescription>();
            var allDependencies = new Dictionary<string, DependencyDescription>();

            // All exports are returned. When the same library name have a ReferenceAssembly type export and a Package type export
            // both will be listed as dependencies. Prefix "fx/" will be added to ReferenceAssembly type dependency.
            foreach (var export in allExports.Values)
            {
                allSourceFiles.AddRange(export.SourceReferences.Select(f => f.ResolvedPath));
                var diagnostics = diagnosticsLookup[export.Library].ToList();
                var description = DependencyDescription.Create(export.Library, diagnostics, allExports);
                allDependencies[description.Name] = description;

                var projectDescription = export.Library as ProjectDescription;
                if (projectDescription != null)
                {
                    if (projectDescription.Identity.Name != context.ProjectFile.Name)
                    { 
                        allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
                    }
                }
                else
                {
                    allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
                }
            }

            snapshot.RootDependency = context.ProjectFile.Name;
            snapshot.TargetFramework = context.TargetFramework;
            snapshot.SourceFiles = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.CompilerOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration);
            snapshot.ProjectReferences = allProjectReferences.OrderBy(reference => reference.Name).ToList();
            snapshot.FileReferences = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.DependencyDiagnostics = allDependencyDiagnostics;
            snapshot.Dependencies = allDependencies;

            return snapshot;
        }
开发者ID:ericstj,项目名称:cli,代码行数:53,代码来源:ProjectContextSnapshot.cs


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