views:

16

answers:

2

Dear ladies and sirs.

I have a class A, which implements interface I:

class A: I
{
  // implementation of I
}

There is another interface J, which extends I:

interface J : I
{
  // J methods and properties.
}

I would like to emit a dynamic class B, which would look like so:

class B : A, J
{
  // All the constructors of A
  // All the methods of J, which are not implemented by A. Their implementation would just throw NotImplementedException()
}

I have enough knowledge in Reflection.Emit to do it from scratch, but, alas, I do not really wish to. Does anyone know a library, which can do that?

Thanks.

P.S.

I am aware of the Castle project, but never really used it and do not know whether they have a ready solution for me.

A: 

When you create type definition by DefineType there is override with base class and implemented interfaces: http://msdn.microsoft.com/en-us/library/f53tx4x8.aspx

Andrey
This is the least of the problems. One has to emit the exact constructors, then all the methods not already implemented by A. This is much more work than simply invoke DefineType.
mark
yes you have to all that stuff yourself. in case of C# compiler either does it for you or enforce you by compilation errors. Reflection.Emit is pretty low level api.
Andrey
A: 

Castle DynamicProxy can be used to do it.

Krzysztof Koźmic