Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml.Serialization Inheritance: System.EnumSyntax
Summary
Specifies when a property or field is ignored on serialization and deserialization.Usage
XmlIgnoreCondition says when a member is left out. Use it in two places: the Condition property of [XmlIgnore], for one member, and XmlSerializerOptions.DefaultIgnoreCondition, for every member. It is the counterpart of JsonIgnoreCondition.
The following example serializes one object with three of the values that make sense as a default:
Remarks
The values and their meaning are those ofSystem.Text.Json.Serialization.JsonIgnoreCondition.
Considerations
Alwayshas an effect only on[XmlIgnore]. SettingDefaultIgnoreConditiontoAlwaysthrows anArgumentException, because it would leave out every member.WhenWritingDefaultincludesnull. For a value type it compares with the default value, so0,false, and0001-01-01are left out. Be careful with it when a default value is meaningful to the reader of the XML.- A
nullcollection wrapped with[XmlArray]is left out byWhenWritingNull,WhenWritingNullReference, andWhenWritingDefault, as any othernullmember is. WhenReadingdoesn’t stop a constructor parameter of the same name from being filled. On a required member it is an error, because the member could never be read: the serializer throws anInvalidOperationExceptionwhen the type is first used.WhenWritingNull,WhenWritingNullReference,WhenWritingDefault, andWhenWritingdon’t affect reading. There are no conditions that apply to reading only.- A member that is left out can’t be told apart from a member that was never set. If the reader needs to see an explicit
null, keepNeverand let the serializer writexsi:nil="true". See Handle null values. - Collections follow their own rules for empty and
null. See Serialize collections.
Values
Related APIs
- CloudNimble.Text.Xml.Serialization.XmlIgnoreAttribute
- CloudNimble.Text.Xml.XmlSerializerOptions