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


C# IGrouping.GroupBy方法代码示例

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


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

示例1: CreateAttendanceDTO

 private static DeptWiseAttendanceDTO CreateAttendanceDTO(IGrouping<int, ActivityLogDTO> grp, IEnumerable<Employee> allEmployees)
 {
     var deptMembers = allEmployees.Where(e => e.Deprtment.Id == grp.First().Department.Id);
     var dto = new DeptWiseAttendanceDTO
     {
         DepartmentName = grp.First().Department.Name,
         Attendance = grp.GroupBy(gd => gd.Employee.Id)
                         .Select(empGroup => new AttendanceDTO
                         {
                             EmployeeName = empGroup.First().Employee.Name,
                             EmployeeId = empGroup.First().Employee.Id,
                             Attended = true,
                             Date = empGroup.First().TimeStamp.ToString("yyyy-MM-dd")
                         })
                         .ToList()
     };
     var absents = deptMembers.Where(m => !dto.Attendance.Any(a => a.EmployeeId == m.Id));
     var date = dto.Attendance.First().Date;
     dto.Attendance.AddRange(absents.Select(a => new AttendanceDTO
                         {
                             EmployeeName = a.Name,
                             EmployeeId = a.Id,
                             Attended = false,
                             Date = date
                         }));
     return dto;
 }
开发者ID:chakrabar,项目名称:AccessAdmin,代码行数:27,代码来源:ReportGeneratorFacade.cs

示例2: parseClientGroup

 private static IEnumerable<IAutoCompleteListItem> parseClientGroup(IGrouping<ulong, Toggl.TogglAutocompleteView> c)
 {
     var projectItems = c.GroupBy(p => p.ProjectID).Select(parseProjectGroup);
     if (c.Key == 0)
         return projectItems;
     var clientName = c.First().ClientLabel;
     return new ClientCategory(clientName, projectItems.ToList()).Yield<IAutoCompleteListItem>();
 }
开发者ID:Nukil,项目名称:toggldesktop,代码行数:8,代码来源:AutoCompleteControllers.cs

示例3: Calc

 public void Calc(IGrouping<string, SpecItem> itemGroup, SpecTable specTable)
 {
    // itemGroup - элементы одной группы.
    // Нужно сгруппировать по ключевому свойству
    var uniqRecs = itemGroup.GroupBy(m => m.Key).OrderBy(m => m.Key, new AcadLib.Comparers.AlphanumComparator());
    
    foreach (var urec in uniqRecs)
    {
       SpecRecord rec = new SpecRecord(urec.Key, urec.ToList(), specTable);
       Records.Add(rec);
    }
 }
开发者ID:vildar82,项目名称:SpecBlocks,代码行数:12,代码来源:SpecGroup.cs

示例4: WriteGroup

        private static void WriteGroup(IGrouping<int, Packet> groups)
        {
            var groupDir = groups.GroupBy(p => p.Direction);
            foreach (var group in groupDir)
            {
                var fileName = Folder + "/" + Opcodes.GetOpcodeName(groups.Key, group.Key) + ".pkt";

                using (var fileStream = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                    using (var writer = new BinaryWriter(fileStream, _encoding))
                        foreach (var packet in group)
                        {
                            writer.Write((ushort)packet.Opcode);
                            writer.Write((int)packet.Length);
                            writer.Write((byte)packet.Direction);
                            writer.Write((ulong)Utilities.GetUnixTimeFromDateTime(packet.Time));
                            writer.Write(packet.GetStream(0));
                        }
            }
        }
开发者ID:samaelsacred,项目名称:WowPacketParser,代码行数:19,代码来源:SplitBinaryPacketWriter.cs

示例5: DescriptionGroupToApiDeclaration

        private ApiDeclaration DescriptionGroupToApiDeclaration(IGrouping<string, ApiDescription> descriptionGroup)
        {
            var modelSpecsBuilder = new ModelSpecsBuilder();

            // Group further by relative path - each group corresponds to an ApiSpec
            var apiSpecs = descriptionGroup
                .GroupBy(ad => ad.RelativePath)
                .Select(dg => DescriptionGroupToApiSpec(dg, modelSpecsBuilder))
                .ToList();

            return new ApiDeclaration
                {
                    apiVersion = "1.0",
                    swaggerVersion = SwaggerVersion,
                    basePath = _basePathAccessor(),
                    resourcePath = descriptionGroup.Key,
                    apis = apiSpecs,
                    models = modelSpecsBuilder.Build()
                };
        }
开发者ID:shiftoff,项目名称:Swashbuckle,代码行数:20,代码来源:ApiExplorerAdapter.cs

示例6: CreateDeclaration

        private ApiDeclaration CreateDeclaration(IGrouping<string, ApiDescription> apiDescriptionGroup)
        {
            var modelSpecRegistrar = new ModelSpecRegistrar();

            // Group further by relative path - each group corresponds to an ApiSpec
            var apiSpecs = apiDescriptionGroup
                .GroupBy(apiDesc => apiDesc.RelativePath)
                .Select(apiDescGrp => CreateApiSpec(apiDescGrp, modelSpecRegistrar))
                .ToList();

            return new ApiDeclaration
            {
                ApiVersion = "1.0",
                SwaggerVersion = SwaggerVersion,
                BasePath = _basePathResolver().TrimEnd('/'),
                ResourcePath = apiDescriptionGroup.Key,
                Apis = apiSpecs,
                Models = modelSpecRegistrar.ToDictionary()
            };
        }
开发者ID:kevinforbes,项目名称:Swashbuckle,代码行数:20,代码来源:SwaggerGenerator.cs

示例7: WriteGroup

        private static void WriteGroup(IGrouping<int, Packet> groups)
        {
            var groupDir = groups.GroupBy(p => p.Direction);
            foreach (var group in groupDir)
            {
                var fileName = "Fusion.pkt";

                using (var fileStream = new FileStream(fileName, FileMode.Append, FileAccess.Write))
                    using (var writer = new BinaryWriter(fileStream, _encoding))
                        foreach (var packet in group)
                        {
                            writer.Write((ushort)packet.Opcode);
                            writer.Write((int)packet.Length);
                            writer.Write((byte)packet.Direction);
                            writer.Write((ulong)Utilities.GetUnixTimeFromDateTime(packet.Time));
                            writer.Write(packet.GetStream(0));
                            // TODO: Add ConnIdx in a backwards compatible way
                        }
            }
        }
开发者ID:TrinityCore,项目名称:WowPacketParser,代码行数:20,代码来源:FusionBinaryPacketWriter.cs

示例8: CreateDeclaration

        private ApiDeclaration CreateDeclaration(IGrouping<string, ApiDescription> apiDescriptionGroup)
        {
            var complexModels = new Dictionary<string, DataType>();

            // Group further by relative path - each group corresponds to an Api
            var apis = apiDescriptionGroup
                .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                .Select(apiDescGrp => CreateApi(apiDescGrp, complexModels))
                .OrderBy(api => api.Path)
                .ToList();

            return new ApiDeclaration
            {
                SwaggerVersion = SwaggerVersion,
                ApiVersion = _apiVersion,
                BasePath = _basePath,
                ResourcePath = apiDescriptionGroup.Key,
                Apis = apis,
                Models = complexModels
            };
        }
开发者ID:kevynb,项目名称:Swashbuckle,代码行数:21,代码来源:SwaggerGenerator.cs

示例9: AssignSeverityAndEnvironmentSeverityList

        /// <summary>
        /// Assigns the severity and environment severity list.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="bugItem">The bug item.</param>
        private static void AssignSeverityAndEnvironmentSeverityList(IGrouping<byte?, ProjectPortalBugsBySeverityAndEnvironment> environment, EnvironmentBugList bugItem)
        {
            var severityGroupedBugList = environment.GroupBy(bugType => bugType.Severity);

            foreach (var severity in severityGroupedBugList)
            {
                SeverityBug severityItem = new SeverityBug();

                severityItem.WorkItemCount = severity.Sum(bugType => bugType.WorkItemCount) ?? 0;

                switch (severity.Key)
                {
                    case SeverityCritical:
                        bugItem.CriticalBug = severityItem;
                        break;

                    case SeverityHigh:
                        bugItem.HighBug = severityItem;
                        break;

                    case SeverityMedium:
                        bugItem.MediumBug = severityItem;
                        break;

                    case SeverityLow:
                        bugItem.LowBug = severityItem;
                        break;
                }
            }
        }
开发者ID:JaipurAnkita,项目名称:mastercode,代码行数:35,代码来源:ProjectDashboardPresenter.cs

示例10: ProcessBout

 private void ProcessBout(IGrouping<int, Jam> boutJamSet, IGrouping<int, PenaltyGroup> penaltyGroups, Dictionary<int, JamTimeEstimate> estimateMap)
 {
     // first, we do the approximations
     var periods = boutJamSet.GroupBy(j => j.IsFirstHalf);
     foreach (IEnumerable<Jam> jams in periods)
     {
         var jamIDs = jams.Select(j => j.ID);
         int totalSeconds = 1800;
         // we'll assume four clock stoppages per half, then add time in as necessary
         totalSeconds -= 30 * (jams.Count() - 5);
         int minTime = 0;
         int maxTime = 0;
         foreach (int jamID in jamIDs)
         {
             minTime += estimateMap[jamID].Minimum;
             maxTime += estimateMap[jamID].Maximum;
         }
         totalSeconds -= minTime;
         if (totalSeconds < 0)
         {
             // just assume the min time for everything
             foreach (Jam jam in jams)
             {
                 var jamLimit = estimateMap[jam.ID];
                 jamLimit.Estimate = jamLimit.Minimum;
             }
         }
         else
         {
             int difference = maxTime - minTime;
             double ratio = ((double)(totalSeconds)) / difference;
             if (ratio > 1.0)
             {
                 Console.WriteLine("Bout: " + jams.First().BoutID + " has a period that the maximums don't fill");
                 ratio = 1.0;
             }
             foreach (Jam jam in jams)
             {
                 var jamLimit = estimateMap[jam.ID];
                 jamLimit.Estimate = jamLimit.Minimum + (int)((jamLimit.Maximum - jamLimit.Minimum) * ratio);
             }
         }
     }
 }
开发者ID:ndilday,项目名称:wftdastats,代码行数:44,代码来源:DurationEstimatesCalculator.cs

示例11: AssignSeverityAndBugTypeSeverityList

        /// <summary>
        /// Assigns the severity and bug type severity list.
        /// </summary>
        /// <param name="bugType">Type of the bug.</param>
        /// <param name="bugItem">The bug item.</param>
        private static void AssignSeverityAndBugTypeSeverityList(IGrouping<string, ProjectPortalBugsBySeverityAndBugType> bugType, EnvironmentBugList bugItem)
        {
            var severityGroupedBugList = bugType.GroupBy(bugTypeItem => bugTypeItem.Severity);

            foreach (var severityItem in severityGroupedBugList)
            {
                var severityBug = new SeverityBug();

                severityBug.WorkItemCount = severityItem.Sum(bugTypeItem => bugTypeItem.WorkItemCount) ?? 0;

                switch (severityItem.Key)
                {
                    case SeverityCritical:
                        bugItem.CriticalBug = severityBug;
                        break;

                    case SeverityHigh:
                        bugItem.HighBug = severityBug;
                        break;

                    case SeverityMedium:
                        bugItem.MediumBug = severityBug;
                        break;

                    case SeverityLow:
                        bugItem.LowBug = severityBug;
                        break;
                }
            }
        }
开发者ID:JaipurAnkita,项目名称:mastercode,代码行数:35,代码来源:ProjectDashboardPresenter.cs

示例12: ValidateOperationMetadataGroup

        /// <summary>
        /// Validates a group of operations with the same context Uri.
        /// </summary>
        /// <param name="operations">Operations to validate.</param>
        private void ValidateOperationMetadataGroup(IGrouping<string, ODataOperation> operations)
        {
            Debug.Assert(operations != null, "operations must not be null.");
            Debug.Assert(operations.Any(), "operations.Any()");
            Debug.Assert(operations.All(o => this.GetOperationMetadataString(o) == operations.Key), "The operations should be grouped by their metadata.");

            if (operations.Count() > 1 && operations.Any(o => o.Target == null))
            {
                throw new ODataException(OData.Core.Strings.ODataJsonLightEntryAndFeedSerializer_ActionsAndFunctionsGroupMustSpecifyTarget(operations.Key));
            }

            foreach (IGrouping<string, ODataOperation> operationsByTarget in operations.GroupBy(this.GetOperationTargetUriString))
            {
                if (operationsByTarget.Count() > 1)
                {
                    throw new ODataException(OData.Core.Strings.ODataJsonLightEntryAndFeedSerializer_ActionsAndFunctionsGroupMustNotHaveDuplicateTarget(operations.Key, operationsByTarget.Key));
                }
            }
        }
开发者ID:TomDu,项目名称:odata.net,代码行数:23,代码来源:ODataJsonLightEntryAndFeedSerializer.cs

示例13: getCurrentInvoiceType

 /// <summary>
 /// Gibt Auftraege zurueck, die dem Rechnungstyp entsprechen
 /// </summary>
 /// <param name="type">Rechnungstyp</param>
 /// <param name="groupedOrder">Auftragsgruppe</param>
 /// <returns></returns>
 private IEnumerable<IGrouping<string, VirtualOrder>> getCurrentInvoiceType(InvoiceTypes type, IGrouping<string, VirtualOrder> groupedOrder)
 {
     IEnumerable<IGrouping<string, VirtualOrder>> _invoiceTypeGroup=null;
     if ((type != null) && type.InvoiceTypeName == "Sammelrechnung")
     {
         _invoiceTypeGroup = groupedOrder.GroupBy(q => q.LocationName.ToString());
     }
     if ((type != null) && type.InvoiceTypeName == "Einzelrechnung")
     {
         _invoiceTypeGroup = groupedOrder.GroupBy(q => q.OrderNumber.ToString());
     }
     if ((type != null) && type.InvoiceTypeName == "Wochenrechnung")
     {
         _invoiceTypeGroup = groupedOrder.GroupBy(q => Math.Floor((decimal)q.ExecutionDate.Value.DayOfYear / 7).ToString());
     }
     if ((type != null) && type.InvoiceTypeName == "Monatsrechnung")
     {
         _invoiceTypeGroup = groupedOrder.GroupBy(q => q.ExecutionDate.Value.Month.ToString());
     }
     return _invoiceTypeGroup;
 }
开发者ID:HedinRakot,项目名称:KVS,代码行数:27,代码来源:DoJob.cs

示例14: RunTestClass

        private static bool RunTestClass(IMessageSink messageSink, IGrouping<ITypeInfo, XunitTestCase> group, RunSummary classSummary)
        {
            bool cancelled = false;
            var aggregator = new ExceptionAggregator();

            Type testClassType = ((IReflectionTypeInfo)group.Key).Type;
            Dictionary<Type, object> fixtureMappings = new Dictionary<Type, object>();
            List<object> constructorArguments = new List<object>();

            // TODO: Read class fixtures from test collection
            foreach (var iface in testClassType.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IClassFixture<>)))
            {
                Type fixtureType = iface.GetGenericArguments().Single();
                object fixture = null;
                aggregator.Run(() => fixture = Activator.CreateInstance(fixtureType));
                fixtureMappings.Add(fixtureType, fixture);
            }

            var ctors = testClassType.GetConstructors();
            if (ctors.Length != 1)
            {
                aggregator.Add(new TestClassException("A test class may only define a single public constructor."));
            }
            else
            {
                var ctor = ctors.Single();
                List<string> unusedArguments = new List<string>();

                foreach (var paramInfo in ctor.GetParameters())
                {
                    object fixture;

                    if (fixtureMappings.TryGetValue(paramInfo.ParameterType, out fixture))
                        constructorArguments.Add(fixture);
                    else
                        unusedArguments.Add(paramInfo.ParameterType.Name + " " + paramInfo.Name);
                }

                if (unusedArguments.Count > 0)
                    aggregator.Add(new TestClassException("The following constructor arguments did not have matching fixture data: " + String.Join(", ", unusedArguments)));
            }

            var methodGroups = group.GroupBy(tc => tc.Method);

            foreach (var method in methodGroups)
            {
                if (!messageSink.OnMessage(new TestMethodStarting { ClassName = group.Key.Name, MethodName = method.Key.Name }))
                    cancelled = true;
                else
                    cancelled = RunTestMethod(messageSink, constructorArguments.ToArray(), method, classSummary, aggregator);

                if (!messageSink.OnMessage(new TestMethodFinished { ClassName = group.Key.Name, MethodName = method.Key.Name }))
                    cancelled = true;

                if (cancelled)
                    break;
            }

            foreach (var fixture in fixtureMappings.Values.OfType<IDisposable>())
            {
                try
                {
                    fixture.Dispose();
                }
                catch (Exception ex)
                {
                    if (!messageSink.OnMessage(new ErrorMessage(ex.Unwrap())))
                        cancelled = true;
                }
            }

            return cancelled;
        }
开发者ID:johnkg,项目名称:xunit,代码行数:73,代码来源:XunitTestFrameworkExecutor.cs

示例15: AssignEnvironmentAndTypeList

        /// <summary>
        /// Assigns the environment and type list.
        /// </summary>
        /// <param name="environment">The environment.</param>
        /// <param name="bugItem">The bug item.</param>
        private static void AssignEnvironmentAndTypeList(IGrouping<byte?, ProjectPortalBugsByEnvironmentAndBugType> environment, EnvironmentBugList bugItem)
        {
            var severityGroupedBugList = environment.GroupBy(bugType => bugType.BugType);

            foreach (var severity in severityGroupedBugList)
            {
                SeverityBug severityItem = new SeverityBug();

                severityItem.WorkItemCount = severity.Sum(bugType => bugType.WorkItemCount) ?? 0;

                switch (severity.Key)
                {
                    case CodeDefect:
                        bugItem.CodeDefect = severityItem;
                        break;

                    case SpecIssue:
                        bugItem.SpecIssue = severityItem;
                        break;

                    case Suggestion:
                        bugItem.Suggestion = severityItem;
                        break;
                }
            }
        }
开发者ID:JaipurAnkita,项目名称:mastercode,代码行数:31,代码来源:ProjectDashboardPresenter.cs


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