[英]Inter process communication for transferring tree structure
我想將一棵 UI 對象樹從進程 A 傳輸到 B。即進程 B 想知道進程 A 中窗口的布局。我發現下面的鏈接幾乎是我需要的,但此鏈接中的方法只能很好地傳輸對象- 定義的結構。 關聯
雖然我要轉移樹結構:我事先不知道布局。
誰能給我一些提示? 多謝!
我認為你的項目看起來像下面的代碼。 您可能需要自定義序列化程序或從您的進程中創建一個樹來填充窗口和控件。 從你的描述中不確定什么是最好的處理方式。
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.