Exemple #1
0
        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());
            }
        }
Exemple #2
0
        public static void AppendOperationTree(
            this SemanticModel model,
            SyntaxNode node,
            StringBuilder actualTextBuilder,
            int initialIndent = 0
            )
        {
            IOperation operation = model.GetOperation(node);

            if (operation != null)
            {
                string operationTree = OperationTreeVerifier.GetOperationTree(
                    model.Compilation,
                    operation,
                    initialIndent
                    );
                actualTextBuilder.Append(operationTree);
            }
            else
            {
                actualTextBuilder.Append(
                    $"  SemanticModel.GetOperation() returned NULL for node with text: '{node.ToString()}'"
                    );
            }
        }