简体   繁体   中英

IronPython adding namespace to scope in C#

I have following C# code

namespace API
{
    public class AutoRcu
    {
        private ...

        public AutoRcu() 
        {
            ...
        }

        public void pressKey(string name)
        {
            ...
        }
    ...
}

I am running following IronPython code to operate C# code.

rcu.pressKey("Menu")

Ths works fine but the question is:
I would like to change Python API to run:

API.rcu.pressKey()

instead of

rcu.pressKey()

How to do that?

Now I add such a class by using

pyScope.SetVariable("rcu",AutoRcu)   

function.

Well, you're essentially creating an object that has a property rcu that is an instance of your AutoRcu class. Just create the object.

dynamic api = new ExpandoObject();
api.rcu = new AutoRcu();
pyScope.SetVariable("API", api);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM