public void Dictionary_Generic_RemoveKey_ValidKeyContainedInDictionary(int count)
        {
            SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count);
            TKey   missingKey = GetNewKey(dictionary);
            TValue outValue;
            TValue inValue = CreateTValue(count);

            dictionary.Add(missingKey, inValue);
            Assert.True(dictionary.Remove(missingKey, out outValue));
            Assert.Equal(count, dictionary.Count);
            Assert.Equal(inValue, outValue);
            Assert.False(dictionary.TryGetValue(missingKey, out outValue));
        }
示例#2
0
            public CurrentNodes(SyntaxNode root)
            {
                // there could be multiple nodes with same annotation if a tree is rewritten with
                // same node injected multiple times.
                var map = new SegmentedDictionary <SyntaxAnnotation, List <SyntaxNode> >();

                foreach (var node in root.GetAnnotatedNodesAndTokens(IdAnnotationKind).Select(n => n.AsNode() !))
                {
                    Debug.Assert(node is object);
                    foreach (var id in node.GetAnnotations(IdAnnotationKind))
                    {
                        List <SyntaxNode>?list;
                        if (!map.TryGetValue(id, out list))
                        {
                            list = new List <SyntaxNode>();
                            map.Add(id, list);
                        }

                        list.Add(node);
                    }
                }

                _idToNodeMap = map.ToImmutableSegmentedDictionary(kv => kv.Key, kv => (IReadOnlyList <SyntaxNode>)ImmutableArray.CreateRange(kv.Value));
            }