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;
Converting string to property type
Re: Converting string to property type
How about using:
Code: Select all
Globals.Tags.myBool.Value = Convert.ToBoolean("false");
Globals.Tags.myFloat.Value = Convert.ToDouble("994.4");
Globals.Tags.myInt.Value = Convert.ToInt16("30");