"TEK" wrote:
having a base class that declares a property as internal causes the call
below (not actual code) to return null instead of the property.
myType.GetProperty(myObject, "MyProperty", BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Instance)
Is this a bug?
Sure looks that way.
Particularly since one the Beta of V2.0 of the .NET Framework it behaves as
you'd expect.
I'm using this:
public class Base
{
internal int BaseInternProp { get { return 42; } }
protected int BaseProtProp { get { return 42; } }
}
public class Foo : Base
{
internal int InternProp { get { return 42; } }
protected int ProtProp { get { return 42; } }
}
and this:
Type t = typeof(Foo);
foreach (MemberInfo fi in t.GetProperties(BindingFlags.Instance |
BindingFlags.NonPublic))
{
Console.WriteLine(fi.Name);
}
Output from VS.NET 2005 Beta 1:
InternProp
ProtProp
BaseInternProp
BaseProtProp
(i.e. what you'd expect.) Output from V1.1 of .NET (i.e. current version):
InternProp
ProtProp
BaseProtProp
Of the two, the first looks like right and the second looks wrong to me.
As far as I can tell this problem only applies to properties. If you use
fields, it all appears to work as you'd expect on both versions of .NET.
--
Ian Griffiths -
http://www.interact-sw.co.uk/iangblog/
DevelopMentor -
http://www.develop.com/