Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Reflection: Fix FormatException when querying ParameterInfo.DefaultValue of optional (closed generic) enum parameter#17917

Merged
1 commit merged intodotnet:masterfrom
stakx:issue-corefx-29570
May 8, 2018
Merged

Reflection: Fix FormatException when querying ParameterInfo.DefaultValue of optional (closed generic) enum parameter#17917
1 commit merged intodotnet:masterfrom
stakx:issue-corefx-29570

Conversation

@stakx
Copy link
Copy Markdown

@stakx stakx commented May 8, 2018

This is similar to #17877, but about enums instead of DateTime. This should fix https://github.com/dotnet/corefx/issues/29570.

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.)

/cc @atsushikan

This is related to dbcfd2f, 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.)
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reflection: ParameterInfo.DefaultValue can throw FormatException for enum parameters

2 participants