互通有两个DLL但不知道对方

问题描述 投票:-1回答:1

我需要一个结构作为未在指定的DLL已知函数的参数。

我要处理两个不同的类型。的类型为两个不同的DLL生成。我实例化很多通过XML序列化的类型。第三方应用程序加载的dll文件,并开始从给定的XML文件做例子。然后我遍历实例,从DLL调用一个函数做一些像出口。在处理我得到全球的数据,我想分享的一个实例。对这个问题是,他们不知道全局数据。他们只拿到了一个函数参数的typeof(对象)。如果我实现在每个这些dll我不能丢在该结构的相同结构,因为DLL A和DLL B是不同的。所以我可以做什么......?

//Third party application
object globalData = null; //Type is not known in this application

//serialisation here...
I_SVExternalFruitExport[] instances = serialisation(....);

foreach(I_SVExternalFruitExport sv in instances)
{
    globalData = sv.ProcessMyType(globalData, sv);
}

//--------------------------------------------------------
// one DLL AppleExport implements I_SVExternalFruitExport
using Apple.dll

struct s_mytype // s_mytype  is known in this dll
{
    List<string> lines;
    ...
}
local_sv;
public object ProcessMyType(object s_TypeStruct, object sv)
{
     local_sv = (Apple)sv;
    if(globalData != null) globalData = new s_mytype();
    else globalData = (s_mytype)s_TypeData;
    //Do Stuff
    return globalData;
}


//--------------------------------------------------------
// second DLL OrangeExport  implements I_SVExternalFruitExport 
using Orange.dll

struct s_mytype    //s_mytype  is known in this dll
{
    List<string> lines;
    ...
}
Orange local_sv;   // Orange is known because of using Orange.dll

public object ProcessMyType(object s_TypeStruct, object sv)
{
    local_sv = (Orange)sv;
    if(globalData != null) globalData = new s_mytype();
    else globalData = (s_mytype)s_TypeData; //This cast says... s_TypeData is not s_mytype because of two dlls A and B but i know they have the same structure.
    //Do Stuff
    return globalData;
}

我需要在我的DLL,但不是在第三方应用已知的结构,因为我想我再生的DLL,可能与在struct一些更多的信息。我不想每次我改变我的dll的时间来更新我的第三方应用程序。

c# dll
1个回答
0
投票

我觉得我得到了一个答案:我会让我的结构s_mytype {}也可序列化:

[Serializable]
public struct s_mytype
{
    public List<string> lines;
    [System.Xml.Serialization.XmlElementAttribute("Lines", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string[] Lines 
    { 
       get { return lines.ToArray(); } 
       set { lines.AddRange(value); } 
    }
}

我的功能“ProcessMyType()”现在必须返回XML数据的字符串:

public string ProcessMyType(object s_TypeStruct, object sv)

现在唯一的问题是,这是一个“苹果”或“橙色”的每个实例都必须先deserilize的XML,并越做越大,每个实例。我的发电机给garantee,在每一个DLL是相同的结构s_mytype。

也许这篇文章使问题更加清晰。如果有一个更简单的方法或类似反序列化少过载的方式,请让我知道。

© www.soinside.com 2019 - 2024. All rights reserved.