Method builders generate parameters with HasDefaultValue set to false
System.Reflection.Emit.ConstructorBuilder and System.Reflection.Emit.MethodBuilder now generate method parameters that, when reflected on, have ParameterInfo.HasDefaultValue set to false
.
Previous behavior
Previously, ConstructorBuilder and MethodBuilder generated IL for method parameters where the HasDefaultValue of the parameters was set to true
.
New behavior
Starting in .NET 8, ConstructorBuilder and MethodBuilder generate IL for method parameters where the HasDefaultValue of the parameters is set to false
, which is the expected value.
Version introduced
.NET 8 Preview 5
Type of breaking change
This change is a behavioral change.
Reason for change
The previous behavior was incorrect, as no default parameter values were specified when the method or constructor was defined.
Recommended action
If you use TypeBuilder.DefineConstructor or TypeBuilder.DefineMethod, make sure consumers of the generated types' methods don't rely on the ParameterInfo.HasDefaultValue property being true
.