Created
March 31, 2017 09:03
-
-
Save Dheer-Rajpoot/4cd13d6f72bb38cbc76c0de0f412f041 to your computer and use it in GitHub Desktop.
This file contains 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 class XMLElementValueReader : IValueReader | |
{ | |
public readonly string ElementName; | |
public XMLElementValueReader(string elementName) | |
{ | |
this.ElementName = elementName; | |
} | |
public CanReadResult CanRead(object source, DataAccessContext context) | |
{ | |
bool flag = source != null && source is XmlNode; | |
return new CanReadResult() | |
{ | |
CanReadValue = flag | |
}; | |
} | |
public ReadResult Read(object source, DataAccessContext context) | |
{ | |
var flag = false; | |
object readValue = (object)null; | |
var xmlNode = source as XmlNode; | |
if (xmlNode != null) | |
{ | |
for (int i = 0; i < xmlNode.ChildNodes.Count; i++) | |
{ | |
if (ElementName.Equals(xmlNode.ChildNodes[i].Name,StringComparison.OrdinalIgnoreCase)) | |
{ | |
readValue = xmlNode.ChildNodes[i].InnerText; | |
flag = true; | |
break; | |
} | |
} | |
} | |
return new ReadResult(DateTime.Now) | |
{ | |
WasValueRead = flag, | |
ReadValue = readValue | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment