samfundev/KtaneTwitchPlays

ReflectionHelper.GetValue does not work with properties of non-nullable value types

Closed this issue · 0 comments

While working on a modified version of Twitch Plays, I noticed that trying to use ReflectionHelper.GetValue<int> to read a property would return 0 instead of the actual value.

The problem seems to be the use of the ?? operator with a generic type that isn't necessarily nullable:

return (T) ((fieldMember != null ? fieldMember.GetValue(target) : default(T)) ?? (propertyMember != null ? propertyMember.GetValue(target, null) : default(T)));