語言

JsonSerializerOptions.RespectRequiredConstructorParameters 屬性

定義

取得或設定一個值,指示在反序列化過程中是否應指定非可選建構參數。

public:
 property bool RespectRequiredConstructorParameters { bool get(); void set(bool value); };
public bool RespectRequiredConstructorParameters { get; set; }
member this.RespectRequiredConstructorParameters : bool with get, set
Public Property RespectRequiredConstructorParameters As Boolean

屬性值

例外狀況

此特性是在序列化或反序列化發生後設定的。

備註

基於歷史原因,基於建構子的反序列化預設將所有建構參數視為可選,當 JSON 有效載荷中不存在時,則以預設值填補缺失參數。 此旗標允許使用者根據需要 JsonSerializerOptions 切換該行為。 此屬性的預設設定可透過「System.Text.Json.Serialization.RespectRequiredConstructorParametersDefault」功能切換,在全應用程式範圍內切換。

建議新應用程式將此屬性與密切相關的RespectNullableAnnotations屬性結合為 true。

適用於