Reflection: Fix DefaultValue exception with enums (#17917)
authorstakx <stakx@eml.cc>
Tue, 8 May 2018 17:42:25 +0000 (19:42 +0200)
committerAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Tue, 8 May 2018 17:42:25 +0000 (10:42 -0700)
commit6f0bb947138c6f75a1721fef7f6c54d4b01282dc
tree8f0b67270bd16fb50ed5e01405f9fd26aa84f384
parent2d68d032723f934f46018767f46dc534d4fc6c1f
Reflection: Fix DefaultValue exception with enums (#17917)

This is related to dbcfd2f9d1, but about enums instead of `DateTime`.

Given e.g. a generic method with a parameter `T arg = default(T)`
where `T` is the generic type parameter, if that is instantiated with
some enum as the generic type argument, then querying the default
value of `arg` using `ParameterInfo.[Raw]DefaultValue` will throw a
`FormatException`.

(The use of generics means that the C# compiler always records a
`null` constant in metadata, which isn't usually the case for enums.)
src/mscorlib/src/System/Reflection/MdConstant.cs