private void MultiplySelf(T unit, int power) { if (unit is AbstractCompound <T, TCompound> ) { // Don't nest compounds, unroll AbstractCompound <T, TCompound> compound = unit as AbstractCompound <T, TCompound>; foreach (KeyValuePair <T, int> factor in compound._factors) { MultiplySelf(factor.Key, power * factor.Value); } } else { IncreaseFactor(unit, power); } }
public bool Equals(T other) { if (other == null || other.GetType() != GetType()) { return(false); } AbstractCompound <T, TCompound> compound = other as AbstractCompound <T, TCompound>; if (compound != null && _factors.Count == compound._factors.Count) // compound is never null, check disables warning { foreach (KeyValuePair <T, int> factor in _factors) { if (!compound._factors.ContainsKey(factor.Key) || compound._factors[factor.Key] != factor.Value) { return(false); } } return(true); } return(false); }