public FieldCollection <T> Update(long fieldId, Func <T, T> updater) { Guard.NotNull(updater, nameof(updater)); if (!ById.TryGetValue(fieldId, out var field)) { return(this); } var newField = updater(field); if (ReferenceEquals(newField, field)) { return(this); } if (!(newField is T typedField)) { throw new InvalidOperationException($"Field must be of type {typeof(T)}"); } return(Clone(clone => { clone.fieldsOrdered = clone.fieldsOrdered.Replace(field, typedField); })); }
public FieldCollection <T> Remove(long fieldId) { if (!ById.TryGetValue(fieldId, out var field)) { return(this); } return(Clone(clone => { clone.fieldsOrdered = fieldsOrdered.Remove(field); })); }
public FieldCollection <T> Remove(long fieldId) { if (!ById.TryGetValue(fieldId, out _)) { return(this); } return(Clone(clone => { clone.fieldsOrdered = fieldsOrdered.Where(x => x.Id != fieldId).ToArray(); })); }
private bool RemoveSubscriptionLocked(string From, string Id, bool RemoveFromThings) { if (!this.subscriptionsByJID.TryGetValue(From, out Dictionary <string, Subscription> ById)) { return(false); } if (!ById.TryGetValue(Id, out Subscription Subscription)) { return(false); } ById.Remove(Id); if (ById.Count == 0) { this.subscriptionsByJID.Remove(From); } if (!RemoveFromThings) { return(true); } Subscription.Active = false; foreach (ThingReference Ref in Subscription.Nodes) { if (!this.subscriptionsByThing.TryGetValue(Ref, out LinkedList <Subscription> Subscriptions)) { continue; } if (!Subscriptions.Remove(Subscription)) { continue; } if (Subscriptions.First == null) { this.subscriptionsByThing.Remove(Ref); } } return(true); }