JsonSerializerOptions.RespectRequiredConstructorParameters 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個值,指示在反序列化過程中是否應指定非可選建構參數。
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。