简体   繁体   English

传递树结构的进程间通信

[英]Inter process communication for transferring tree structure

I want to transfer a tree of UI objects from process A to B. ie Process B want to know the layout of windows in process A. I found below link nearly what I need, but the method in this link can only transfer objects with well-defined structure.我想将一棵 UI 对象树从进程 A 传输到 B。即进程 B 想知道进程 A 中窗口的布局。我发现下面的链接几乎是我需要的,但此链接中的方法只能很好地传输对象- 定义的结构。 link 关联

While I am going to transfer tree structure: I do not know the layout beforehand.虽然我要转移树结构:我事先不知道布局。

Can anyone give me some hints?谁能给我一些提示? thanks a lot!多谢!

I think you project would look like the code below.我认为你的项目看起来像下面的代码。 You may need a custom serializer or to create a tree from your process that fills in the windows and controls.您可能需要自定义序列化程序或从您的进程中创建一个树来填充窗口和控件。 Not sure from you description what is the best way of proceeding.从你的描述中不确定什么是最好的处理方式。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Process process = new Process();

            XDocument doc = new XDocument("root");

            XElement xProcess = SerializeToXml<Process>.Serialize(process);
            doc.Add(xProcess);

        }

    }

    public class SerializeToXml <T>
    {
        public static XElement Serialize(T data)
        {
            StringWriter writer = new StringWriter();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            XmlWriter xWriter = XmlWriter.Create(writer, settings);


            XmlSerializer serializer = new XmlSerializer(data.GetType());

            serializer.Serialize(xWriter, data);

            XmlReader reader = XmlReader.Create(xWriter.ToString());

            writer.Close();

            return (XElement)XElement.ReadFrom(reader);
        } 
    }
    public class Process
    {
        public List<Window> windows { get; set; }
    }
    public class Window
    {
        public List<Control> controls { get; set; }
    }
    public class Control
    {
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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