D
D
Dmitry Petrov2013-06-21 11:43:46
.NET
Dmitry Petrov, 2013-06-21 11:43:46

Dynamic type generation or wrappers around interfaces in PCL?

For my needs, I'm trying to make a proxy class generator around interfaces. That is, suppose there is an interface

interface ITest
{
    void DoTest(int arg1);
}

There is a helper class
class Helper
{
    protected object proxyCaller(MethodInfo executingMethod, params object[] args) { ... }
}

In the usual ClassLibrary, it was possible to generate a class that inherits from Helper and the specified interface (for example, ITest) using AssemblyBuilder and TypeBuilder .
ITest obj = GetInstanceFor<ITest>();
obj->DoTest(1);

Calling obj->DoTest results in a call to proxyCaller, in which I can do already conscious actions and return the result.
In short, it turns out a transparent proxy, only with your own hands.
There was a task to do the same for PCL, so that the library could be used for WP8, Win8, Android (Mono, there is, they say, support for PCL with a tambourine). But, as it turned out, in PCL the Reflection.Emit mechanism is either missing or severely cut off - type- and assemblybuilder are not available.
Tell me, please, is there a way to implement a similar dynamic wrapper for interfaces without additional libraries?
I tried to do it through DynamicObject (I didn’t work with them before), but it didn’t work out for me, although it looked tempting

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question