* ParameterBuilder.SetConstant(nonNull) for TEnum?
This change makes it possible to use `ParameterBuilder.SetConstant`
to set a non-null default value for parameters having a nullable enum
type.
* ParameterInfo.DefaultValue for TEnum?
Add a note to `MdConstant.GetValue` (which sits behind `ParameterInfo.
[Raw]DefaultValue`) explaining why changing its behavior to mirror the
change in `TypeBuilder.SetConstantValue` would be a breaking change.
Commit migrated from https://github.com/dotnet/coreclr/commit/
f1c47fa7d2cdf29c5d0d1d7c89855e0d0ee5518a
if (destType.IsByRef)
destType = destType.GetElementType();
+ // Convert nullable types to their underlying type.
+ // This is necessary for nullable enum types to pass the IsEnum check that's coming next.
+ destType = Nullable.GetUnderlyingType(destType) ?? destType;
+
if (destType.IsEnum)
{
// | UnderlyingSystemType | Enum.GetUnderlyingType() | IsEnum
if (fieldType.IsEnum && raw == false)
{
+ // NOTE: Unlike in `TypeBuilder.SetConstantValue`, if `fieldType` describes
+ // a nullable enum type `Nullable<TEnum>`, we do not unpack it to `TEnum` to
+ // successfully enter this `if` clause. Default values of `TEnum?`-typed
+ // parameters have been reported as values of the underlying type, changing
+ // this now might be a breaking change.
+
long defaultValue = 0;
switch (corElementType)