1

I am making a scripting program using MS ClearScript. I would like to be able to reference to a property indirectly without having to type out the value member of my class.

Here is my class:

namespace WpfApp1
{
    public class TagIO
    {
        public string name { get; set; }
        public int value { get; set; }
    }
}

I create a collection and add the hostobjects to the scriptengine as the following:

ObservableCollection<TagIO> InputCollection = new ObservableCollection<TagIO>();

foreach (var InputTag in InputCollection)
{
   if (InputTag != null)
     scriptEngine.AddHostObject(InputTag.name, InputTag);
}

I can run a script with the following line:

a.value = b.value;

But I would like to improve this so that I can do the following:

a = b;
PigSpider
  • 881
  • 9
  • 18

1 Answers1

2

Instead of using AddHostObject, do this:

scriptEngine.Script[InputTag.name] = InputTag;
BitCortex
  • 3,328
  • 1
  • 15
  • 19
  • That works. Thanks. Just having an issue with changing a hostObject directly from the scriptengine. I am Manually setting the Tag to the engine's value: OutputTag = .Engine.Script[Output name]; – PigSpider Nov 25 '19 at 15:20