本文整理汇总了C#中IReadOnlyList.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyList.GroupBy方法的具体用法?C# IReadOnlyList.GroupBy怎么用?C# IReadOnlyList.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReadOnlyList
的用法示例。
在下文中一共展示了IReadOnlyList.GroupBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadChangeScripts
private void LoadChangeScripts()
{
var scripts = new DirectoryInfo(path);
Files = scripts.GetFiles("*.sql", SearchOption.AllDirectories)
.Select(x => ScriptFile.Load(x))
.OrderBy(x => x)
.ToList();
var duplicates = Files.GroupBy(x => x.FileNameHash).Where(x => x.Count() > 1);
if (duplicates.Any())
{
var sb = new StringBuilder();
foreach (var duplicate in duplicates)
{
sb.AppendLine($"Duplicate Filename Detected: \"{duplicate.First().FileName}\"");
foreach (var file in duplicate)
{
sb.AppendLine($"\t\"{file.FilePath}\"");
}
}
sb.AppendLine();
sb.AppendLine("All filenames must be unique. Including those in separate subdirectories.");
throw new Exception(sb.ToString());
}
}
示例2: DeclarationFinder
public DeclarationFinder(
IReadOnlyList<Declaration> declarations,
IEnumerable<CommentNode> comments,
IEnumerable<IAnnotation> annotations)
{
_comments = comments.GroupBy(node => node.QualifiedSelection.QualifiedName)
.ToDictionary(grouping => grouping.Key, grouping => grouping.ToArray());
_annotations = annotations.GroupBy(node => node.QualifiedSelection.QualifiedName)
.ToDictionary(grouping => grouping.Key, grouping => grouping.ToArray());
_declarationsByName = declarations.GroupBy(declaration => new
{
IdentifierName = declaration.Project != null &&
declaration.DeclarationType == DeclarationType.Project
? declaration.Project.Name
: declaration.IdentifierName
})
.ToDictionary(grouping => grouping.Key.IdentifierName, grouping => grouping.ToArray());
}
示例3: LoadTypes
private void LoadTypes()
{
m_allTypes = new LiftedList<TypeDefinition>(
MetadataTable.TypeDef.RowCount(m_peFile),
index => m_peFile.GetRow(new ZeroBasedIndex(index), MetadataTable.TypeDef),
pRow => new TypeDefinition((TypeDefRow*)pRow, this),
() => m_peFile.IsDisposed
);
var nestedTypes = new LiftedValueTypeList<NestedTypeInfo>(
MetadataTable.NestedClass.RowCount(m_peFile),
index=>m_peFile.GetRow(new ZeroBasedIndex(index), MetadataTable.NestedClass),
x=> {
var pRow = (NestedClassRow*) x;
return new NestedTypeInfo(
m_allTypes[((ZeroBasedIndex)(pRow->GetNestedClass(m_peFile))).Value],
m_allTypes[((ZeroBasedIndex)(pRow->GetEnclosingClass(m_peFile))).Value]
);
},
()=>m_peFile.IsDisposed
);
var enclosingTypes = nestedTypes.Select(x => x.NestedType.DeclaringType = x.EnclosingType).ToHashSet();
m_allTypes.GroupBy(x => x.DeclaringType).ForEach(
x => (x.Key ?? (IMutableTypeContainer)this).Types = x.ToList().AsReadOnly()
);
m_allTypes.Where(
x => !enclosingTypes.Contains(x)
).ForEach(
(IMutableTypeContainer x) => x.Types = new List<TypeDefinition>().AsReadOnly()
);
}
示例4: RemoveInheritedInverseNavigations
private IReadOnlyList<RelationshipCandidate> RemoveInheritedInverseNavigations(
IReadOnlyList<RelationshipCandidate> relationshipCandidates)
{
var relationshipCandidatesByRoot = relationshipCandidates.GroupBy(r => r.TargetTypeBuilder.Metadata.RootType())
.ToDictionary(g => g.Key, g => g.ToList());
foreach (var relationshipCandidatesHierarchy in relationshipCandidatesByRoot.Values)
{
var filteredRelationshipCandidates = new HashSet<RelationshipCandidate>();
foreach (var relationshipCandidate in relationshipCandidatesHierarchy)
{
RemoveInheritedInverseNavigations(
relationshipCandidate, relationshipCandidatesHierarchy, filteredRelationshipCandidates);
}
}
return relationshipCandidates;
}
示例5: GetDuplicatedVersion
private int? GetDuplicatedVersion(IReadOnlyList<Migration> migrations)
{
int duplicatedVersion = migrations
.GroupBy(x => x.Version)
.Where(x => x.Count() > 1)
.Select(x => x.Key)
.FirstOrDefault();
return duplicatedVersion == 0 ? (int?)null : duplicatedVersion;
}