/// <summary> /// Creates an empty copy of whatever object this memento can reconstitute. Some /// mementos are only able to reconstitute into their source objects (they can only /// be used to restore state in the same object), and these mementos will return a /// reference to that object.) /// </summary> /// <returns>ISupportsMementos.</returns> public ISupportsMementos CreateTarget() { Substance substance = (Substance)m_materialType.CreateMass(m_mass, m_temperature); if (m_matlSpecs != null) { substance.SetMaterialSpecs(m_matlSpecs); } return(substance); }
/// <summary> /// Applies the material specs. /// </summary> /// <param name="emitted">The emitted.</param> /// <param name="original">The original.</param> public static void ApplyMaterialSpecs(Substance emitted, Substance original) { _Debug.Assert(emitted.MaterialType.Equals(original.MaterialType)); ArrayList emittedSpecs = new ArrayList(); foreach (DictionaryEntry de in original.GetMaterialSpecs()) { Guid specGuid = (Guid)de.Key; double specMass = (double)de.Value; double origPctg = specMass / original.Mass; double emittedMass = emitted.Mass * origPctg; emittedSpecs.Add(new DictionaryEntry(specGuid, emittedMass)); } emitted.SetMaterialSpecs(emittedSpecs); }
/// <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); }