Hi,
I just discovered a very strange behavior with Type.GetInterface and nested Types.
The following sample code will show the problem, I am using the Type.FullName of an interface to check whether a given type derives from that interface:
public interface IStandardInterface {}
public class StandardClass : IStandardInterface {}
class Program
{
public interface INestedInterface {}
public class NestedClass : INestedInterface { }
static void Main()
{
var stdIfName = typeof (IStandardInterface).FullName;
var nestedIfName = typeof (INestedInterface).FullName;
var std = typeof(StandardClass).GetInterface(stdIfName);
var nested = typeof(NestedClass).GetInterface(nestedIfName);
}
}
If I execute the code above it works for StandardClass but not for NestedClass.
- std has a value of typeof(IStandardInterface)
- nested has a value of null
Is this behavior expected or a bug? If it is expected could you explain why?
I use .net Framework version 3.5 SP1.