internal static void VerifyClone(SemanticModel model) { foreach (var node in model.SyntaxTree.GetRoot().DescendantNodes()) { var operation = model.GetOperation(node); if (operation == null) { continue; } var clonedOperation = model.CloneOperation(operation); // check whether cloned IOperation is same as original one var original = OperationTreeVerifier.GetOperationTree(model.Compilation, operation); var cloned = OperationTreeVerifier.GetOperationTree(model.Compilation, clonedOperation); Assert.Equal(original, cloned); // make sure cloned operation is value equal but doesn't share any IOperations var originalSet = new HashSet <IOperation>(operation.DescendantsAndSelf()); var clonedSet = new HashSet <IOperation>(clonedOperation.DescendantsAndSelf()); Assert.Equal(originalSet.Count, clonedSet.Count); Assert.Equal(0, originalSet.Intersect(clonedSet).Count()); } }