Converting string to property type
Posted: Tue Jul 09, 2013 3:57 am
I have a list of tags with values of the type Float, bool ,int16 etc. and i want to convert the value(string) to the appropriate type of the tag. However i get an error when i try to set myTag.Value to the converted value. Am i
missing something?
private GlobalDataItem GetGlobalDataItem(string propertyName)
{
PropertyInfo tagProperty = typeof (Neo.ApplicationFramework.Generated.Tags).GetProperty(propertyName);
if(tagProperty == null)
return null;
else
return tagProperty.GetValue(Globals.Tags, null) as GlobalDataItem;
}
var myTag = GetGlobalDataItem(tagName);
PropertyInfo tagProperty = typeof (Neo.ApplicationFramework.Generated.Tags).GetProperty(tagName);
var tagVal = Convert.ChangeType(value, tagProperty.PropertyType,null);
myTag.Value = tagVal;
missing something?
private GlobalDataItem GetGlobalDataItem(string propertyName)
{
PropertyInfo tagProperty = typeof (Neo.ApplicationFramework.Generated.Tags).GetProperty(propertyName);
if(tagProperty == null)
return null;
else
return tagProperty.GetValue(Globals.Tags, null) as GlobalDataItem;
}
var myTag = GetGlobalDataItem(tagName);
PropertyInfo tagProperty = typeof (Neo.ApplicationFramework.Generated.Tags).GetProperty(tagName);
var tagVal = Convert.ChangeType(value, tagProperty.PropertyType,null);
myTag.Value = tagVal;