Skip to content

Instantly share code, notes, and snippets.

@Dheer-Rajpoot
Created March 31, 2017 09:03
Show Gist options
  • Save Dheer-Rajpoot/4cd13d6f72bb38cbc76c0de0f412f041 to your computer and use it in GitHub Desktop.
Save Dheer-Rajpoot/4cd13d6f72bb38cbc76c0de0f412f041 to your computer and use it in GitHub Desktop.
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