Changed MiniYaml.NodesDict property into a method.

Method is now called ToDictionary.
- Cached a few invocations into locals which should prevent some redundant evaluation.
- Added ToDictionary overloads that take projection functions for the keys and elements, since several callsites were doing a subsequent Linq.ToDictionary call to get this.
This commit is contained in:
RoosterDragon
2014-05-21 05:14:16 +01:00
parent 334a210231
commit 2e992a7310
21 changed files with 104 additions and 74 deletions

View File

@@ -193,12 +193,17 @@ namespace OpenRA.Mods.RA.Widgets.Logic
static IEnumerable<NewsItem> ReadNews(byte[] bytes)
{
var str = Encoding.UTF8.GetString(bytes);
return MiniYaml.FromString(str).Select(node => new NewsItem
return MiniYaml.FromString(str).Select(node =>
{
Title = node.Value.NodesDict["Title"].Value,
Author = node.Value.NodesDict["Author"].Value,
DateTime = FieldLoader.GetValue<DateTime>("DateTime", node.Key),
Content = node.Value.NodesDict["Content"].Value
var nodesDict = node.Value.ToDictionary();
return new NewsItem
{
Title = nodesDict["Title"].Value,
Author = nodesDict["Author"].Value,
DateTime = FieldLoader.GetValue<DateTime>("DateTime", node.Key),
Content = nodesDict["Content"].Value
};
});
}