public Schema AddField(Field field) { Guard.NotNull(field, nameof(field)); if (FieldsByName.ContainsKey(field.Name) || FieldsById.ContainsKey(field.Id)) { throw new ArgumentException($"A field with name '{field.Name}' and id {field.Id} already exists.", nameof(field)); } return(Clone(clone => { clone.fieldsOrdered = clone.fieldsOrdered.Add(field); })); }
public Schema ReorderFields(List <long> ids) { Guard.NotNull(ids, nameof(ids)); if (ids.Count != fieldsOrdered.Length || ids.Any(x => !FieldsById.ContainsKey(x))) { throw new ArgumentException("Ids must cover all fields.", nameof(ids)); } return(Clone(clone => { clone.fieldsOrdered = fieldsOrdered.OrderBy(f => ids.IndexOf(f.Id)).ToImmutableArray(); })); }