Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
shotter way to set value from xml reader
private static void SetValue(Language language, XmlReader reader, string name)
{
// Note: Not yet tested!
var path = name.Split('/');
var currentType = typeof(Language);
// get 1st prop => General -> General/Title
System.Reflection.PropertyInfo propInfo = currentType.GetProperty(path[0]); // if Name/type then -> Name
for (int i = 1; i < path.Length; i++)
{
propInfo = propInfo.DeclaringType.GetProperty(path[i]);
// Property doesn't exits in current type!
if (propInfo == null)
{
break;
}
}
propInfo.SetValue(language, reader.Value, null);
// ======================================
switch (name)
{
case "Name":
language.Name = reader.Value;
break;
case "General/Title":
language.General.Title = reader.Value;
break;
case "General/Version":
language.General.Version = reader.Value;
break;
case "General/TranslatedBy":
language.General.TranslatedBy = reader.Value;
break;
case "General/CultureName":
language.General.CultureName = reader.Value;
break;
case "General/HelpFile":
language.General.HelpFile = reader.Value;
break;
case "General/Ok":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.