System.Reflection.Emit.ConstructorBuilder 和 System.Reflection.Emit.MethodBuilder 现在生成方法参数,在反映时,ParameterInfo.HasDefaultValue 设置为 false
。
以前的行为
以前,ConstructorBuilder 和 MethodBuilder 为方法参数生成 IL,其中参数 HasDefaultValue 设置为 true
。
新行为
从 .NET 8 开始,ConstructorBuilder 和 MethodBuilder 为方法参数生成 IL,其中参数的 HasDefaultValue 被设置为 false
,这是预期值。
已引入的版本
.NET 8 预览版 5
破坏性变更的类型
此更改为行为更改。
更改原因
以前的行为不正确,因为定义方法或构造函数时未指定默认参数值。
建议的措施
如果使用TypeBuilder.DefineConstructor或TypeBuilder.DefineMethod,请确保生成类型的方法的使用者不会依赖ParameterInfo.HasDefaultValue属性为true
。