方法生成器生成参数,HasDefaultValue 设置为 false

System.Reflection.Emit.ConstructorBuilderSystem.Reflection.Emit.MethodBuilder 现在生成方法参数,在反映时,ParameterInfo.HasDefaultValue 设置为 false

以前的行为

以前,ConstructorBuilderMethodBuilder 为方法参数生成 IL,其中参数 HasDefaultValue 设置为 true

新行为

从 .NET 8 开始,ConstructorBuilderMethodBuilder 为方法参数生成 IL,其中参数的 HasDefaultValue 被设置为 false,这是预期值。

已引入的版本

.NET 8 预览版 5

破坏性变更的类型

此更改为行为更改

更改原因

以前的行为不正确,因为定义方法或构造函数时未指定默认参数值。

如果使用TypeBuilder.DefineConstructorTypeBuilder.DefineMethod,请确保生成类型的方法的使用者不会依赖ParameterInfo.HasDefaultValue属性为true

受影响的 API