mono/MonoGame — pull request #1503 by RayBatts (2013-03-06 02:53:22+00:00)
Title: ReflectiveReader 'bug'

First off, I know this PR is going to look crazy. It took me quite a while to figure out why our game wasn't working anymore.

This PR fixes a bug found in the reflective reader. It turns out that there's some odd behavior in .NET when it comes to using Type.GetAllProperties() with an abstract class, causing inherited properties to be pulled in anyway.

Suppose you have the following two classes:

public class DerivedClass : BaseClass
{
public override string NameOfProperty { get; set; }
}

public abstract class BaseClass
{
public abstract string NameOfProperty { get; set; }
}

For whatever reason, you override a property and didn't change it's implementation. Calling

typeof(DerivedClass).GetAllProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

Will still return NameOfProperty as one of it's properties (Even with the DeclaredOnly binding flag). Because of this, an extra check is needed to make sure we the ContentReader isn't attempting to read in the same property twice. I ran this against our game on Windows 8 and iOS, seeing the problem fixed without any adverse affects.

I've also tested this against stock .NET to make sure I wasn't going crazy. But the setup above will still return the inherited property.