From fdcdb4697a67408a82d9b357ee655082b8ea111f Mon Sep 17 00:00:00 2001 From: Cezar Cretu Date: Tue, 18 Mar 2014 04:02:55 +0200 Subject: [PATCH] minor XmlReader refactoring --- RequireJsNet/Configuration/XmlReader.cs | 61 +++++++++++++++++-------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/RequireJsNet/Configuration/XmlReader.cs b/RequireJsNet/Configuration/XmlReader.cs index 3a268ed..2fa4d4b 100644 --- a/RequireJsNet/Configuration/XmlReader.cs +++ b/RequireJsNet/Configuration/XmlReader.cs @@ -59,20 +59,30 @@ private RequireShim GetShim(XElement root) if (shimEl != null) { shim.ShimEntries = shimEl.Descendants("dependencies") - .Select(r => new ShimEntry - { - Exports = r.Attribute("exports") != null ? r.Attribute("exports").Value : "", - For = r.Attribute("for").Value, - Dependencies = r.Descendants("add") - .Select(x => new RequireDependency - { - Dependency = x.Attribute("dependency").Value - }).ToList() - }).ToList(); + .Select(ShimEntryReader).ToList(); } return shim; } + private ShimEntry ShimEntryReader(XElement element) + { + return new ShimEntry + { + Exports = element.Attribute("exports") != null ? element.Attribute("exports").Value : "", + For = element.Attribute("for").Value, + Dependencies = DependenciesReader(element) + }; + } + + private List DependenciesReader(XElement element) + { + return element.Descendants("add") + .Select(x => new RequireDependency + { + Dependency = x.Attribute("dependency").Value + }).ToList(); + } + private RequireMap GetMap(XElement root) { var map = new RequireMap(); @@ -81,19 +91,30 @@ private RequireMap GetMap(XElement root) if (mapEl != null) { map.MapElements = mapEl.Descendants("replace") - .Select(r => new RequireMapElement - { - For = r.Attribute("for").Value, - Replacements = r.Descendants("add") - .Select(x => new RequireReplacement - { - NewKey = x.Attribute("new").Value, - OldKey = x.Attribute("old").Value - }).ToList() - }).ToList(); + .Select(MapElementReader).ToList(); } return map; } + + + private RequireMapElement MapElementReader(XElement element) + { + return new RequireMapElement + { + For = element.Attribute("for").Value, + Replacements = ReplacementsReader(element) + }; + } + + private List ReplacementsReader(XElement element) + { + return element.Descendants("add") + .Select(x => new RequireReplacement + { + NewKey = x.Attribute("new").Value, + OldKey = x.Attribute("old").Value + }).ToList(); + } } }