简体   繁体   中英

Communicate with main window class from CodeDom compiled code C# Wpf

As the title suggests I am having a bit of trouble communicating with my wpf application's MainWindow.cs class during runtime when the code compiles.

Context: This is a application I am writing for myself that utilizes CodeDom's compiler to compile code stored in xml format at runtime or in a triggered event(like a button or voice command)

The compiler is working neatly but I have been stuck at communicating with my classes from the original application.(MainWindow.cs)

I would like to be able to call functions and access variables from within the runtime compiled CodeDom Scripts. I have found method invoking but I don't quite understand how it works yet, any help would be appreciated!

Example of what I want to do:

Main Window Class Example

namespace WpfOverlay
{

    public partial class MainWindow : Window
    {
        public string AccessThis;


        public void ExampleFunctionToAccess(string InputString)
        {
            AccessThis = InputString;
        }
    }
}

And access that class to call ExampleFunctionToAccess(); from a CodeDom Compiled script/class in a different namespace (if possible I wouldn't mind having them in the same namespace)

The fact that you compile it at runtime has no bearing on your actual problem, what you actually want is to implement any of the myriad forms possible of IPC.

I recommend an UDP client/server approach, it's relatively easy to implement robustly.

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