I have created a type like this:
TypeBuilder tb = moduleBuilder.DefineType(myname, TypeAttributes.Class |
TypeAttributes.Public, typeof(BaseClass), new Type[] { typeof(ImyInterface) });
Then lots of ilgenerating code follows for constructors, methods etc. When I start using the class I noticed something strange. I want to check whether the type 'myname' that i created really implements the ImyInterface. I would expect that both of the following statements return true:
// t is Type 'myName'
Type baseInterface = t.GetInterface(typeof(ImyInterface).name);
if (baseType != null)
{
// this is actually true, as I expected
}
if (typeof(ImyInterface).isAssignableFrom(t))
{
// the if clause is false, but I don't have a clue why??
}
So I have created a class that implements ImyInterface but which is not assignable to an object of type ImyInterface, what am I missing?
By the way, there are no generics involved and the Interface is just a basic one to test the concept:
public interface ITestInterface
{
int CalcSquaredInteger(int number);
}