copyWith method

XmlEntity copyWith({
  1. String? name,
  2. String? value,
  3. bool? isSystem,
  4. bool? isPublic,
  5. List<XmlEntity>? externalEntities,
  6. String? ndata,
  7. bool copyNull = false,
})

Copies this entity with the provided values.

name must be > 0 in length if not null.

Either isSystem or isPublic may be true, not both.

If copyNull is true, value, externalEntities, and ndata will be copied with a value of null if they're not provided with another value, otherwise they will default to this element's values.

Implementation

XmlEntity copyWith({
  String? name,
  String? value,
  bool? isSystem,
  bool? isPublic,
  List<XmlEntity>? externalEntities,
  String? ndata,
  bool copyNull = false,
}) {
  assert(name == null || name.isNotEmpty);
  assert(isPublic == null || isSystem == null || !(isPublic && isSystem));

  if (!copyNull) {
    value ??= this.value;
    externalEntities ??= this.externalEntities;
    ndata ??= this.ndata;
  }

  return XmlEntity(
    name ?? this.name,
    value!,
    isSystem: isSystem ?? (isPublic == true ? false : this.isSystem),
    isPublic: isPublic ?? (isSystem == true ? false : this.isPublic),
    externalEntities: externalEntities,
    ndata: ndata,
  );
}