如何对嵌套属性进行分组并在 LINQ 中具有相同的父级?
我是 LINQ
的新手,在组织此查询以返回我想要的内容时遇到困难。首先,一些背景知识。我正在开发一款音乐游戏,它支持自定义音符图表。笔记图表包含特定于笔记集合的元数据,例如笔记数量、难度和 BPM。一个或多个笔记图表可以位于 simfile 中,该文件类似于笔记图表的容器。 simfile 也有自己的“simfile 级”元数据,例如歌曲文件的路径、歌曲标题、歌曲艺术家等。因此,我有以下形式的类:
class Notechart {
public List<Note> Notes { get; }
public uint BPM { get; set; }
public uint Difficulty { get; set; }
}
class Simfile {
public List<Notechart> Notecharts { get; }
public string SongPath { get; set; }
public string SongTitle { get; set; }
public string SongArtist { get; set; }
// Other "album-specific" fields...
}
对于给定的 List
,我想获取所有 Simfiles
中包含的所有 Notecharts
的列表,并按以下条件分组(按优先顺序排列):
1) Notechart.
的值,其中
是任意 Notechart 特定字段或 Notechart 特定字段的转换(例如任何 BPM 介于 130-150 之间)
2)位于同一个 Simfile
中(因为如果 simfile 中的两个 notecharts 具有与上述相同的条件,我希望将它们与 simfile 中的信息一起显示)
是否可以在 <代码>LINQ? MyElement
和 MyElementCollection
没有实现任何自定义相等性检查,因此我不相信测试它是否在列表中会起作用。谢谢!
I'm new to LINQ
, and I'm having trouble organizing this query to return what I want. First off, some background. I'm working on a music game, which supports custom notecharts. Notecharts contain metadata specific to a collection of notes, such as number of notes, difficulty, and BPM. One or more notecharts can be in a simfile, sort of a container of notecharts. A simfile has its own "simfile-level" metadata as well, such as a path to a song file, song title, song artist, etc. So, I have classes of the following form:
class Notechart {
public List<Note> Notes { get; }
public uint BPM { get; set; }
public uint Difficulty { get; set; }
}
class Simfile {
public List<Notechart> Notecharts { get; }
public string SongPath { get; set; }
public string SongTitle { get; set; }
public string SongArtist { get; set; }
// Other "album-specific" fields...
}
For a given List<Simfile>
, I'd like to get a list of all Notecharts
contained in all the Simfiles
grouped by the following criteria (in order of precedence):
1) The value of Notechart.<Value>
, where <Value>
is any of the notechart-specific fields or a transformation of a notechart-specific field (e.g. any BPMs between 130-150)
2) Being in the same Simfile
(since if two notecharts within a simfile have the same criteria as above, I would want to display them together with information from the simfile)
Is there anyway to represent this in LINQ
? MyElement
and MyElementCollection
don't implement any custom equality checking, so I don't believe testing if it is in the list will work. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论