質問

I've been asked to do something unusual at work. We have some clients which are using applications which make calls to our DLL (let's call it Sdk.dll).

Recently, someone decided to change some namespaces in the Sdk code. If we were to provide this new DLL to our clients, their applications would break.

However, some clients will be writing applications using the new version of the DLL (let's call it Sdk.Updated.dll).

My task is to somehow support both old and new client applications, without recompiling the client apps.

I thought that I could simply replace the old Sdk.dll with a new one, which redirects all the calls to the appropriate callee in Sdk.Updated.dll. However, it seems like it will be tedious to write wrapper classes for each instance where a namespace was changed.

I'm wondering if anyone might have suggestion for a more dynamic way to accomplish this?

So, just to be clear:

Client 1:

using Sdk;

// ...

int sum = new Calc().AddTwoNumbers(3, 4);

Client 2:

using Sdk.Updated;

// ...

int sum = new Calc().AddTwoNumbers(3, 4);

Sdk.Updated.dll:

namespace Sdk.Updated {
    public class Calc {
        public AddTwoNumbers(int x, int y) {
            return x + y;
        }
    }
}

What would be the best way to support both client applications, with the restriction that we can't recompile the client applications?

(As an added wrinkle, some method names may have been changed between Sdk and Sdk.Updated, but I'd rather just get an idea of how to handle the namespace thing first...)

役に立ちましたか?

解決

After some investigation (including using namespace aliases, and building a tool which uses reflection to dynamically generate wrapper DLLs), we have concluded that there is no good way to do this without recompiling the client applications.

In fact, the namespaces should not have been changed without first considering the potential impact on client apps. (I'm sure this will be obvious to anyone reading this.)

Hopefully this saves someone a lot of time (and money) if you are asked to do something similar.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top