我有两个包含 guid 的列表:
var activeSoftware = channels.ByPath("/software/").Children.Where(c => c.StateProperties.IsActive).Select(c => c.Guid);
var activeChannels = channels.ByPath("/game-channels/").Children.Where(c => c.StateProperties.IsActive).Select(c => c.Guid);
和另一个游戏列表:
List<MyCms.Content.Games.Game> games = new List<MyCms.Content.Games.Game>();
游戏对象有两个可以使用的属性:
game.gamingproperties.software
- 包含软件的 guid
game.stateproperties.channels
- 逗号分隔的 guid 列表
是的,我知道在字段中保存逗号分隔值不好,但我目前无法更改它(它已经在 40 多个站点上工作)
我想要做的是选择软件处于活动状态的所有游戏(通过比较softwarelist
)game.gamingproperties.software
并且它们出现的频道处于活动状态(通过检查是否game.stateproperties.channels
包含任何activechannels
guid)
最初,我这样做是这样的:
foreach (var channel in activeSoftware)
{
foreach (var match in oGames.AllActive.Where(g => !string.IsNullOrEmpty(g.GamingProperties.UrlDirectGame) && g.GamingProperties.Software.Contains(channel) && g.StateProperties.Channels.Split(',').Intersect(activeChannels).Any()))
{
games.Add(match);
}
}
但我确信我可以摆脱那些讨厌的 foreach 并只使用 linq。