/// <summary> /// Replaces this value with the given value. /// </summary> /// <param name="other">The other value.</param> public void Replace(Value other) { Debug.Assert(other != null, "Invalid other node"); Debug.Assert(CanBeReplaced, "Cannot replace a non-replaceable value"); Debug.Assert(!IsReplaced, "Cannot replace a replaced value"); var target = other.Resolve(); Debug.Assert(target != this, "Invalid replacement cycle"); Replacement = target; // Propagate uses foreach (var use in allUses) { Replacement.AddUse(use.Target, use.Index); } // Notify nodes foreach (var use in allUses) { use.Target.OnReplacedNode(use.Index); } OnReplace(); }