I have a collection which I am exposing to a clearscript engine, at the moment I have to specify that the Value property is a static type int so that scripting basic arithmetic as plus or minus will work:
Here's my collection and the class it makes use of that I expose to the script engine:
public class LogicBlockIOCollection : ConcurrentDictionary<string, LogicBlockIO> { }
public class LogicBlockIO
{
public string Name;
public dynamic Value;
}
I am adding host objects to my clearscript egine using the following method:
public void AddBlock(LogicBlockIOCollection Entries)
{
foreach (var Entry in Entries)
{
this[LastBlockID].Engine.Script[Entry.Key] = Entry.Value.Value;
}
}
When I program the LogicBlockIO.Value property as dynamic and run the following script I receive these results:
C = A + B;
C = 1 + 2;
C = 12; //Not 3 as expected
When I program the LogicBlockIO.Value property as integer, and I try to run the same simple script i get the results I expect:
C = 3;
Does someone have a suggestion how it is possible to make use of a single property that may be of different types to achieve what I require?