tags:

views:

96

answers:

4

I am changing the question as it appears to be vague.

I have an interface that forces implementation of n methods. Each method takes different arguments. I use 2 implementations, one in the DMZ and one in my application server. Call them Communicator and Handler, one sends it and the other implements it.

The interface is injected depending on the environment or application they run in. I basically want to pass the arguments over the wire so I can invoke the method exactly as it was called on the DMZ side.

How can I consistently, regardless of the method being called, serialize all of the arguments and pass them over the wire to be invoked in the environment where I can actually exectute them?

+3  A: 

You could to change your TestMethod to receive params array:

public string TestMethod(params object[] args) 
{
    // do stuff
}
Rubens Farias
A: 

Your question is a little confusing, but I think I might know what you're after...

You could use dependency injection/inversion of control from a tool like Ninject. You still have to ask the injection system for instances of objects, but as long as you set up your bindings properly, the DI system will handle wiring up everything for you.

Take a look at the wiki for Ninject to see exactly how this works. It's worth noting that there are a lot of DI/IoC frameworks out there, so you might want to do some research to decide which one looks best to you. The few I can think of off the top of my head are:

Scott Anderson
I updated the question to be more clear, the problem is actually arising out of using DI and probably using in ways I shouldn't
Rob A
A: 

I don't think there is a safe runtime way to access a local variable using its compile time name.

Coincoin
A: 

As far as serialization goes, you can use

    static Type[] MyMethod(int a, string b, DateTime c, object d)
    {
        var myParams = MethodBase.GetCurrentMethod().GetParameters();
        return myParams.Select(p => p.ParameterType).ToArray();
    }

That example shows what kind of types you need to tell your serializer you're dealing with. Obviously my example's a little off, as you won't want your methods returning Type[]... that was for my own testing purposes, but it shows you how to get the types for the current method.

As far as getting the actual values, there seems to be no way to do this unless you use params (as mentioned), or some sort of dynamic proxy (never played with it, not positive it will suit your needs). Otherwise, at runtime, the data is simply inaccessible. See here and here for explanations.

Sapph