互动VS和其他程序

时间:2013-08-14 13:01:35

标签: c#

我编写了一个解析XML的DLL,并返回带有标记名称及其值的Dictionary。我在其他名为ZennoPoster Project Maker的程序中使用它。这是代码:

XMLWork.XMLWorker worker = new XMLWork.XMLWorker(); // My parse class
string path = @"Z:\New\test.xml";
Dictionary<string, string> data = worker.GetData(path); // GetData - method, that returns
                                                        // data from XML
project.Variables["second_name"].Value = data["second_name"]; 

这段代码我必须重新编译成XMLWorker类方法并返回project类型,并且在ZennoPoster中我必须使用1行代码返回数据。我该怎么办?

1 个答案:

答案 0 :(得分:1)

假设您有以下简化类型:

namespace Objects
{
    public class Project
    {
        public Dictionary<string, Variable> Variables { get; set; }
    }
    public  class Variable
    {
        public object Value { get; set; }
    }
}

您可以像这样构建XMLWorker类:

using Objects;

public class XMLWorker
{
    public Project Project { get; private set; }
    public XMLWorker(string path)
    {
        Project = new Project();
        Dictionary<string, string> data = GetData(path);
        Project.Variables["second_name"].Value = data["second_name"];
    }

    internal Dictionary<string, string> GetData(string path)
    {
        // method implementation
    }
}

样本用法:

var project = (new XMLWork.XMLWorker(@"Z:\New\test.xml")).Project;