Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Add functions and property from an Interface to a new API of the engine

0
0
Hi,

I have the following code with a class that expose an interface. I would like to expose my interface to javascript engine, but not using "objects".

    public interface ITest
    {
        void foo(string s);
        //... many other methods
        int bar { get; set; }
    }

    public class Test : ITest
    {
        public void foo(string s)
        {
            MessageBox.Show(s);
        }

        public int bar {get;set;}
    }
The code I would write is this :
                engine.Execute("foo('hello')");
                engine.Execute("bar=6");
But NOT something like
                engine.Execute("myObject.foo('hello')");
                engine.Execute("myObject.bar=6");
So how can I expose all my interface as an API ?
I would like to do something like that :
                ITest t = new Test();
                engine.AddHostObject("", t);
And I would not have to "wrap" each method and property, or if you have generic code that wrap all an interface, I am interested please...

Thanks for advance for your answer
Sybaris

Viewing all articles
Browse latest Browse all 2297