I am attempting to generate a dynamic class implementing an interface, but where one or more of the members already exists in the base. I compiled the following code in C# and examined it in reflector to see what the C# compiler does.
class BaseClass
{
public string Bob
{
get { return "Bob"; }
}
}
interface IStuff
{
string Bob { get; }
}
class SubClass : BaseClass, IStuff
{
}
Reflector does not show any implementation in SubClass.
.class private auto ansi beforefieldinit SubClass
extends Enterprise.Services.OperationalActions.Business.Filters.BaseClass
implements Enterprise.Services.OperationalActions.Business.Filters.IStuff
{
}
But if I do not emit the member explicitly, TypeBuilder.CreateType()
throws an InvalidOperationException
stating that the member does not have an implementation. So my question is, how do I tell TypeBuilder
that an interface member should take it's implementation from the base?