/// <summary> /// Informs the helper that the memento supporter that wraps this helper has gained a child. /// </summary> /// <param name="child">The child.</param> public void AddChild(ISupportsMementos child) { if (child.ReportsOwnChanges) { if (m_children == null) { m_children = new ArrayList(); } if (!m_children.Contains(child)) { m_children.Add(child); child.MementoChangeEvent += m_childChangeHandler; } } else { if (m_problemChildren == null) { m_problemChildren = new ArrayList(); } if (!m_problemChildren.Contains(child)) { m_problemChildren.Add(child); } } ReportChange(); }
/// <summary> /// Informs the helper that the memento supporter that wraps this helper has lost a child. /// </summary> /// <param name="child">The child.</param> public void RemoveChild(ISupportsMementos child) { if (m_children.Contains(child)) { child.MementoChangeEvent -= m_childChangeHandler; } m_children?.Remove(child); m_problemChildren?.Remove(child); }
/// <summary> /// Loads the contents of this Memento into the provided object. /// </summary> /// <param name="ism">The object to receive the contents of the memento.</param> public void Load(ISupportsMementos ism) { Substance substance = (Substance)ism; substance.m_mass = m_mass; substance.Temperature = m_temperature; substance.m_type = m_materialType; if (m_matlSpecs != null) { substance.SetMaterialSpecs(m_matlSpecs); } else { substance.ClearMaterialSpecs(); } OnLoadCompleted?.Invoke(this); }
/// <summary> /// Ascertains equality between this one and the other one. /// </summary> /// <param name="otherOne">The other one.</param> /// <returns><c>true</c> if this one and the other one are equal, <c>false</c> otherwise.</returns> public bool Equals(ISupportsMementos otherOne) { Substance otherSubstance = otherOne as Substance; if (otherSubstance == null) { return(false); } if (m_materialSpecs != null && otherSubstance.m_materialSpecs == null) { return(false); } if (m_materialSpecs == null && otherSubstance.m_materialSpecs != null) { return(false); } if (m_materialSpecs != null) { if (otherSubstance.m_materialSpecs != null && m_materialSpecs.Count != otherSubstance.m_materialSpecs.Count) { return(false); } foreach (DictionaryEntry de in m_materialSpecs) { if (otherSubstance.m_materialSpecs != null && !otherSubstance.m_materialSpecs.Contains(de.Key)) { return(false); } if (otherSubstance.m_materialSpecs != null && !de.Value.Equals(otherSubstance.m_materialSpecs[de.Key])) { return(false); } } } else if (otherSubstance.m_materialSpecs != null) { return(false); } return(m_mass.Equals(otherSubstance.m_mass) && Temp.Equals(otherSubstance.Temp) && m_type.Equals(otherSubstance.m_type)); }
/// <summary> /// Called by the memento supporter that wraps this helper, to let it know that a change has occurred in its internal state. /// </summary> /// <param name="iss">The memento supporter which has changed.</param> private void ReportChange(ISupportsMementos iss) { m_hasChanged = true; MementoChangeEvent?.Invoke(iss); }
/// <summary> /// Initializes a new instance of the <see cref="MementoHelper"/> class. /// </summary> /// <param name="iss">The memento supporter that wraps this helper.</param> /// <param name="wrappeeReportsOwnChanges">if set to <c>true</c> the memento supporter is able to report its own changes.</param> public MementoHelper(ISupportsMementos iss, bool wrappeeReportsOwnChanges) { m_wrappeeReportsOwnChanges = wrappeeReportsOwnChanges; m_iss = iss; m_childChangeHandler = ReportChange; }