Created
July 31, 2012 23:59
-
-
Save henkmeulekamp/3221842 to your computer and use it in GitHub Desktop.
Enumerable stream Xnodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable<T> Stream<T>(string nodeName) | |
{ | |
//move to content | |
_reader.MoveToContent(); | |
// Parse the file by node | |
while (_reader.Read()) | |
{ | |
switch (_reader.NodeType) | |
{ | |
case XmlNodeType.Element: | |
//dont ignore case, xml is case sensitive | |
if (_reader.Name.Equals(nodeName, | |
StringComparison.InvariantCulture)) | |
{ | |
var el = XNode.ReadFrom(_reader) as XElement; | |
if (el != null) | |
yield return DeSerializer<T>(el); | |
} | |
break; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void FirstEmployee() | |
{ | |
using (var reader = GetEnumerableXmlReader()) | |
{ | |
var employee = reader.Stream<Employee>().First(); | |
Assert.IsNotNull(employee); | |
Assert.IsNotNullOrEmpty(employee.EmployeeID); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment