Exemplo n.º 1
0
        public void ContainsKey()
        {
            sut.Add("a", "c");

            sut.ContainsKey("a").Should().BeTrue();
            sut.ContainsKey("b").Should().BeFalse();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes an entry from the list.
        /// If after removing this entry, the opcode list is empty,
        /// the opcode is then removed from the list as well.
        /// </summary>
        /// <param name="opCode">The opcode of the packet.</param>
        /// <param name="size">The size of the packet, in bytes.</param>
        public void Remove(int opCode, int size)
        {
            m_ignoredPackets.Remove(opCode, size);

            if (m_ignoredPackets.ContainsKey(opCode))
            {
                if (m_ignoredPackets[opCode].Count <= 0)
                {
                    m_ignoredPackets.Remove(opCode);
                }
            }
        }
Exemplo n.º 3
0
        public void MultiValueDictionaryContainsTest()
        {
            MultiValueDictionary <Int32, String> dictionary = new MultiValueDictionary <Int32, String>();

            foreach (KeyValuePair <Int32, List <String> > value in this.values)
            {
                dictionary.Add(value.Key, value.Value);
            }

            dictionary.ContainsKey(1).ShouldBeTrue();
            dictionary.ContainsKey(0).ShouldBeFalse();
        }
Exemplo n.º 4
0
        public static void ShouldContainKey()
        {
            var multiDict = new MultiValueDictionary <string, string>();

            multiDict.AddRange("key2", values2);
            multiDict.AddRange("key1", values1);
            multiDict.Add("key3", "海亀");

            Assert.IsTrue(multiDict.ContainsKey("key1"));
            Assert.IsTrue(multiDict.ContainsKey("key3"));
            Assert.IsTrue(multiDict.ContainsKey("key2"));
            Assert.IsTrue(multiDict.Contains("key1"));
            Assert.IsTrue(multiDict.Contains("key2"));
            Assert.IsTrue(multiDict.Contains("key3"));
        }
Exemplo n.º 5
0
Arquivo: Scope.cs Projeto: irpbc/mj
 public override void enterIfAbsent(Symbol c)
 {
     if (!dict.ContainsKey(c.name))
     {
         dict.Add(c.name, c);
     }
 }
Exemplo n.º 6
0
        public virtual void ManyItems()
        {
            var items = Enumerable.Range(0, 100).Select(_ =>
            {
                var key    = NextKey();
                var values = Enumerable.Range(0, 100).Select(__ => NextValue()).ToArray();
                return(new KeyValuePair <TKey, TValue[]>(key, values));
            }).ToDictionary(kv => kv.Key, kv => kv.Value);
            var data = new MultiValueDictionary <TKey, TValue>();

            foreach (var kv in items)
            {
                data.Add(kv.Key, kv.Value);
            }
            var count = data.Count;

            Assert.Equal(100 * 100, count);
            Assert.True(HashSet <TKey> .CreateSetComparer().Equals(new HashSet <TKey>(data.Keys), new HashSet <TKey>(items.Keys)));
            foreach (var key in items.Keys)
            {
                Assert.True(data.ContainsKey(key));
                Assert.True(data.TryGetValue(key, out var v));
                Assert.Contains(v, items[key]);
                Assert.True(data.TryGetValues(key, out var vs));
                count = vs.Length;
                Assert.Equal(100, count);
                Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue>(items[key])));
                var vsx = new List <TValue>();
                Assert.True(data.TryGetValues(key, vsx));
                count = vsx.Count;
                Assert.Equal(100, count);
                Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vsx), new HashSet <TValue>(items[key])));
            }
        }
        public void RemoveTest()
        {
            var t = new MultiValueDictionary <int, int>();

            t.Add(1, 3);
            t.Add(1, 4);
            t.Add(1, 5);
            t.Add(2, 3);
            t.Add(2, 4);

            t.Remove(1);
            Assert.False(t.ContainsKey(1));
            t.Remove(2);
            Assert.False(t.ContainsKey(1));
            Assert.True(!t.Any());
        }
Exemplo n.º 8
0
        private List <string> ReadCardList(string text)
        {
            List <string> cards = new List <string>();

            foreach (string line in Regex.Split(text, "\r\n|\r|\n"))
            {
                var match = CardRegex.Match(line);
                if (match.Success)
                {
                    int    amt  = int.Parse(match.Groups[1].Value);
                    string name = match.Groups[3].Value;
                    if (CardDatabase.ContainsKey(name))
                    {
                        for (int i = 0; i < amt; i++)
                        {
                            cards.Add(name);
                        }
                    }
                    else
                    {
                        lst_notfound.Items.Add(name);
                    }
                }
            }
            return(cards);
        }
Exemplo n.º 9
0
 public IEnumerable <int> Get(TKey key)
 {
     if (!_data.ContainsKey(key))
     {
         return(Enumerable.Empty <int>());
     }
     return(_data[key]);
 }
Exemplo n.º 10
0
 /// <inheritdoc />
 public ICollection <IIndex> GetIndices(IOperationTarget operationTarget)
 {
     if (!_indicesCoverage.ContainsKey(operationTarget))
     {
         return(new IIndex[0]);
     }
     return(_indicesCoverage[operationTarget].ToArray());
 }
 public IEnumerable <ConnectionId> GetConnections(RoomId roomId, ConnectionId except = null)
 {
     // An inexistent room can be requested when the first user enters it (because we requests the list of connections before adding the user's connection to the room)
     if (!_roomsConnections.ContainsKey(roomId))
     {
         return(new List <ConnectionId>());
     }
     return(_roomsConnections [roomId].Where(r => except == null || r != except).ToList());        //without ToList(), result looks like it's null?!
 }
        public void MultiValueDictionaryContainsTest()
        {
            MultiValueDictionary <Int32, String> dictionary = new MultiValueDictionary <Int32, String>();

            foreach (KeyValuePair <Int32, List <String> > item in _items)
            {
                dictionary.Add(item.Key, item.Value);
            }

            Assert.AreEqual(true, dictionary.ContainsKey(1));
            Assert.AreEqual(false, dictionary.ContainsKey(0));

            Assert.AreEqual(true, dictionary.Contains(new KeyValuePair <Int32, ICollection <String> >(1, new List <String> {
                "1", "11"
            } as ICollection <String>)));
            Assert.AreEqual(false, dictionary.Contains(new KeyValuePair <Int32, ICollection <String> >(1, new List <String> {
                "0", "11"
            } as ICollection <String>)));
        }
Exemplo n.º 13
0
 protected void RemoveSagaKeys(string name)
 {
     if (keys.ContainsKey(name))
     {
         Publish(new SagaKeysChangedEvent(
                     keys
                     .Where(x => x.Key != name)
                     .Select(x => new KeyValuePair <string, ImmutableList <string> >(x.Key, x.Value.ToImmutableList()))
                     .ToImmutableDictionary()));
     }
 }
Exemplo n.º 14
0
 public static IEnumerable <TValue> All <TKey, TValue>(this MultiValueDictionary <TKey, TValue> dictonary, TKey key)
 {
     if (dictonary.ContainsKey(key))
     {
         return(dictonary[key]);
     }
     else
     {
         return(Enumerable.Empty <TValue>());
     }
 }
Exemplo n.º 15
0
 public IEnumerable <int> IdsOf(string name)
 {
     if (lookup.ContainsKey(name))
     {
         return(lookup[name]);
     }
     else
     {
         return(Enumerable.Empty <int>());
     }
 }
Exemplo n.º 16
0
 public IEnumerable <string> NamesOf(int id)
 {
     if (names.ContainsKey(id))
     {
         return(names[id]);
     }
     else
     {
         return(Enumerable.Empty <string>());
     }
 }
Exemplo n.º 17
0
    protected override IEnumerable <Node> GetChildren(Node node)
    {
        BGoapNode goapNode = (node as AStarDebugNode).content as BGoapNode;

        if (childLists.ContainsKey(goapNode))
        {
            foreach (var BGoapNode in childLists.GetValues(goapNode, true))
            {
                yield return(new AStarDebugNode(BGoapNode, goal));
            }
        }
    }
Exemplo n.º 18
0
        private static void AddNestedGuids(GuidWithName child, string parentGuid, RelativePath parentFolder, Dictionary <RelativePath, string> folderProjects, MultiValueDictionary <string, GuidWithName> childrenByParentGuid)
        {
            // Check whether there is any siblings with the same name.
            // If so, put this child to the parent of the current parent folder.
            while (childrenByParentGuid.ContainsKey(parentGuid) && childrenByParentGuid[parentGuid].Any(a => a.Name == child.Name))
            {
                parentFolder = parentFolder.GetParent();
                parentGuid   = folderProjects[parentFolder];
            }

            childrenByParentGuid.Add(parentGuid, child);
        }
        public void Remove_ShouldRemoveTheKeyIfNoMoreValuesExist()
        {
            _target.Add("A", "B");
            _target.Remove("A", "B");

            Assert.False(_target.ContainsKey("A"));
        }
Exemplo n.º 20
0
 public void Draw(TagIdent item)
 {
     if (objectInstances.ContainsKey(item))
     {
         //IRenderable @object = objects[item] as IRenderable;
         //@object.Render( new[] { program, systemProgram } );
     }
     else
     {
         var data = Halo2.GetReferenceObject(item);
         //objects[item] = new ScenarioObject( (ModelBlock)data );
     }
 }
Exemplo n.º 21
0
        private bool ExecutedCore(string name, object value = null) {
            value = value ?? typeof(object);
            var keyValuePair = new KeyValuePair<string, ApplicationModulesManager>(name, ModuleManager);
            if (CallMonitor.ContainsKey(keyValuePair)) {
                if (!CallMonitor.GetValues(keyValuePair, true).Contains(value)) {
                    CallMonitor.Add(keyValuePair, value);
                    return false;
                }
                return true;
            }
            CallMonitor.Add(keyValuePair, value);

            return false;
        }
 public IEnumerable <SignificantAasElemRecord> Retrieve(
     AdminShell.AdministrationShellEnv env,
     SignificantAasElement kind)
 {
     if (env == null || true != _records.ContainsKey(kind))
     {
         yield break;
     }
     foreach (var r in _records[kind])
     {
         // look up
         var lo = env.FindReferableByReference(r.Reference);
         if (lo != null)
         {
             r.LiveObject = lo;
             yield return(r);
         }
     }
 }
        public void RemoveTest2()
        {
            var t = new MultiValueDictionary <int, int>();

            t.Add(1, 3);
            t.Add(1, 4);
            t.Add(1, 5);
            t.Add(2, 3);
            t.Add(2, 4);

            t.Remove(1, 3);
            Assert.Equal(new[] { 4, 5 }, t[1].OrderBy(x => x));
            t.Remove(1, 5);
            Assert.Equal(new[] { 4 }, t[1].OrderBy(x => x));
            t.Remove(2, 4);
            Assert.Equal(new[] { 3 }, t[2].OrderBy(x => x));
            t.Remove(1, 4);
            Assert.False(t.ContainsKey(1));
        }
Exemplo n.º 24
0
        public AdminShell.Referable FindReferableByReference(AdminShell.Reference r)
        {
            var hk = ComputeHashOnReference(r);

            if (hk == 0 || !dict.ContainsKey(hk))
            {
                return(null);
            }

            foreach (var test in dict[hk])
            {
                var xx = (test as AdminShell.IGetReference)?.GetReference();
                if (xx != null && xx.Matches(r))
                {
                    return(test);
                }
            }

            return(null);
        }
            public static void Add(SyntaxNode syntaxNode, int identityHash)
            {
                var filePath = syntaxNode.SyntaxTree?.FilePath;

                if (syntaxNode is ICompilationUnitSyntax && filePath != null && _SyntaxNodesFromFilePath.ContainsKey(filePath))
                {
                    // If we've got a new compilation unit syntax then any syntax nodes from the same file won't get used so remove them.
                    foreach (var node in _SyntaxNodesFromFilePath[filePath])
                    {
                        _SyntaxNodeHashes.Remove(node);
                    }
                    _SyntaxNodesFromFilePath.Remove(filePath);
                }

                if (filePath != null)
                {
                    _SyntaxNodesFromFilePath.Add(filePath, syntaxNode);
                }
                _SyntaxNodeHashes.Add(syntaxNode, identityHash);
            }
Exemplo n.º 26
0
        public virtual void EmptyTests()
        {
            var key   = NextKey();
            var empty = new MultiValueDictionary <TKey, TValue>();
            var xvs   = new List <TValue>();

            Assert.False(empty.ContainsKey(key));
            Assert.False(empty.TryGetValue(key, out var _));
            Assert.False(empty.TryGetValues(key, out var arr));
            Assert.Null(arr);
            Assert.False(empty.TryGetValues(key, xvs));
            Assert.Empty(xvs);
            var count = empty.Count;

            Assert.Equal(0, count);
            count = empty.Count();
            Assert.Equal(0, count);
            Assert.Empty(empty.Keys);
            Assert.Equal(0, empty.Remove(key));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)empty).Remove(new KeyValuePair <TKey, TValue>(key, default(TValue))));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)empty).IsReadOnly);
        }
        public T FindElementByReference(
            AdminShell.Reference r,
            AdminShell.Key.MatchMode matchMode = AdminShell.Key.MatchMode.Strict)
        {
            var hk = ComputeHashOnReference(r);

            if (hk == 0 || !dict.ContainsKey(hk))
            {
                return(default(T));
            }

            foreach (var test in dict[hk])
            {
                var xx = (test as AdminShell.IGetReference)?.GetReference();
                if (xx != null && xx.Matches(r, matchMode))
                {
                    return(test);
                }
            }

            return(default(T));
        }
 private static bool MethodCalledFromDispose(MultiValueDictionary<INamedTypeSymbol, IMethodSymbol> disposeMethodsCalledFromDispose, IMethodSymbol dispose)
 {
     return disposeMethodsCalledFromDispose.ContainsKey(dispose.ContainingType) &&
            disposeMethodsCalledFromDispose[dispose.ContainingType].Contains(dispose);
 }
Exemplo n.º 29
0
        public virtual void BasicOperationsTest()
        {
            var    data    = new MultiValueDictionary <TKey, TValue>();
            var    key0    = NextKey();
            var    key1    = NextKey();
            var    value00 = NextValue();
            var    value01 = NextValue();
            var    value10 = NextValue();
            var    value11 = NextValue();
            TValue v;

            TValue[] vs;
            var      xvs = new List <TValue>();

            // single key, single value
            data.Add(key0, value00);
            Assert.True(data.ContainsKey(key0));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.Equal(value00, v);
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.Single(vs, v);
            xvs.Clear();
            Assert.True(data.TryGetValues(key0, xvs));
            Assert.Single(xvs, v);
            var count = data.Count;

            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            Assert.Single(data.Keys, key0);
            data.Clear();
            Assert.Empty(data);
            // single key, two values (added separately)
            data.Add(key0, value00);
            data.Add(key0, value01);
            Assert.True(data.ContainsKey(key0));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            xvs.Clear();
            Assert.True(data.TryGetValues(key0, xvs));
            count = xvs.Count;
            Assert.Equal(2, count);
            Assert.Contains(value00, xvs);
            Assert.Contains(value01, xvs);
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            Assert.Single(data.Keys, key0);
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Remove(new KeyValuePair <TKey, TValue>(key0, value00)));
            count = data.Count;
            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            data.Add(key0, value00);
            Assert.Equal(2, data.Remove(key0));
            Assert.Empty(data);
            // single key, two values (added as enumerable)
            data.Add(key0, value00, value01);
            Assert.True(data.ContainsKey(key0));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            Assert.Single(data.Keys, key0);
            data.Set(key0, value01);
            count = data.Count;
            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            data.Set(key0, value00, value01);
            Assert.Equal(2, data.Remove(key0));
            Assert.Empty(data);
            // single key, two values (added as keyvalue pairs)
            ((ICollection <KeyValuePair <TKey, TValue> >)data).Add(new KeyValuePair <TKey, TValue>(key0, value00));
            ((ICollection <KeyValuePair <TKey, TValue> >)data).Add(new KeyValuePair <TKey, TValue>(key0, value01));
            Assert.True(data.ContainsKey(key0));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            Assert.Single(data.Keys, key0);
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Remove(new KeyValuePair <TKey, TValue>(key0, value00)));
            count = data.Count;
            Assert.Equal(1, count);
            count = data.Count();
            Assert.Equal(1, count);
            data.Add(key0, value00);
            Assert.Equal(2, data.Remove(key0));
            Assert.Empty(data);
            // two keys, two values (added separately)
            data.Add(key0, value00);
            data.Add(key0, value01);
            data.Add(key1, value10);
            data.Add(key1, value11);
            Assert.True(data.ContainsKey(key0));
            Assert.True(data.ContainsKey(key1));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value00)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value01)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value10)));
            Assert.True(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value11)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value00)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key1, value01)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value10)));
            Assert.False(((ICollection <KeyValuePair <TKey, TValue> >)data).Contains(new KeyValuePair <TKey, TValue>(key0, value11)));
            Assert.True(data.TryGetValue(key0, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value00, v) || EqualityComparer <TValue> .Default.Equals(value01, v));
            Assert.True(data.TryGetValues(key0, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value00, value01
            }));
            xvs.Clear();
            Assert.True(data.TryGetValues(key0, xvs));
            count = xvs.Count;
            Assert.Equal(2, count);
            Assert.Contains(value00, xvs);
            Assert.Contains(value01, xvs);
            Assert.True(data.TryGetValue(key1, out v));
            Assert.True(EqualityComparer <TValue> .Default.Equals(value10, v) || EqualityComparer <TValue> .Default.Equals(value11, v));
            Assert.True(data.TryGetValues(key1, out vs));
            Assert.NotNull(vs);
            Assert.True(HashSet <TValue> .CreateSetComparer().Equals(new HashSet <TValue>(vs), new HashSet <TValue> {
                value10, value11
            }));
            xvs.Clear();
            Assert.True(data.TryGetValues(key1, xvs));
            count = xvs.Count;
            Assert.Equal(2, count);
            Assert.Contains(value10, xvs);
            Assert.Contains(value11, xvs);
            count = data.Count;
            Assert.Equal(4, count);
            count = data.Count();
            Assert.Equal(4, count);
            Assert.True(HashSet <TKey> .CreateSetComparer().Equals(new HashSet <TKey>(data.Keys), new HashSet <TKey> {
                key0, key1
            }));
            count = data.Keys.Count();
            Assert.Equal(2, count);
            Assert.Equal(2, data.Remove(key0));
            count = data.Count;
            Assert.Equal(2, count);
            count = data.Count();
            Assert.Equal(2, count);
            data.Clear();
            Assert.Empty(data);
        }
Exemplo n.º 30
0
        public static void ShouldContainKey()
        {
            var multiDict = new MultiValueDictionary<string, string>();
            multiDict.AddRange("key2", values2);
            multiDict.AddRange("key1", values1);
            multiDict.Add("key3", "海亀");

            Assert.IsTrue(multiDict.ContainsKey("key1"));
            Assert.IsTrue(multiDict.ContainsKey("key3"));
            Assert.IsTrue(multiDict.ContainsKey("key2"));
            Assert.IsTrue(multiDict.Contains("key1"));
            Assert.IsTrue(multiDict.Contains("key2"));
            Assert.IsTrue(multiDict.Contains("key3"));
        }
Exemplo n.º 31
0
        private void ParseManagedSemantics()
        {
            var stringTable      = m_context.PathTable.StringTable;
            var magicNugetMarker = PathAtom.Create(stringTable, "_._");
            var dllExtension     = PathAtom.Create(stringTable, ".dll");

            var refs = new MultiValueDictionary <NugetTargetFramework, RelativePath>();
            var libs = new MultiValueDictionary <NugetTargetFramework, RelativePath>();
            var assemblyToTargetFramework = new MultiValueDictionary <PathAtom, NugetTargetFramework>();

            foreach (var relativePath in PackageOnDisk.Contents)
            {
                // This is a dll. Check if it is in a lib folder or ref folder.
                var atoms = relativePath.GetAtoms();
                if (atoms.Length == 3)
                {
                    var libOrRef = atoms[0];
                    var targetFrameworkFolder = atoms[1];
                    var fileName = atoms[2];

                    var isLib = NugetFrameworkMonikers.LibFolderName.CaseInsensitiveEquals(stringTable, libOrRef);
                    var isRef = NugetFrameworkMonikers.RefFolderName.CaseInsensitiveEquals(stringTable, libOrRef);

                    if (isLib || isRef)
                    {
                        if (!TryGetKnownTargetFramework(targetFrameworkFolder, out NugetTargetFramework targetFramework))
                        {
                            // We skip unknown frameworks, packages are not necessarily well constructed. We log this
                            // as a verbose message (i.e., this is not an error).
                            Logger.Log.NugetUnknownFramework(m_context.LoggingContext, PackageOnDisk.Package.Id,
                                                             targetFrameworkFolder.ToString(stringTable), relativePath.ToString(stringTable));
                            continue;
                        }

                        var isManagedEntry = false;
                        var ext            = fileName.GetExtension(stringTable);
                        if (dllExtension.CaseInsensitiveEquals(stringTable, ext))
                        {
                            isManagedEntry = true;
                            if (isRef)
                            {
                                refs.Add(targetFramework, relativePath);
                            }

                            if (isLib)
                            {
                                libs.Add(targetFramework, relativePath);
                            }
                        }
                        else if (fileName == magicNugetMarker)
                        {
                            isManagedEntry = true;
                        }

                        if (isManagedEntry)
                        {
                            IsManagedPackage = true;

                            if (!TargetFrameworkWithFallbacks.ContainsKey(targetFramework.Moniker))
                            {
                                bool comaptibleMonikerAlreadyPresent = false;
                                if (NugetFrameworkMonikers.CompatibilityMatrix.ContainsKey(targetFramework.Moniker))
                                {
                                    foreach (var compatibleMoniker in NugetFrameworkMonikers.CompatibilityMatrix[targetFramework.Moniker])
                                    {
                                        if (TargetFrameworkWithFallbacks.ContainsKey(compatibleMoniker))
                                        {
                                            comaptibleMonikerAlreadyPresent = true;
                                            break;
                                        }
                                    }
                                }

                                if (!comaptibleMonikerAlreadyPresent)
                                {
                                    // If nuspec does not specify target frameworks, we need to infer from the layout
                                    TargetFrameworkWithFallbacks.Add(targetFramework.Moniker);
                                }
                            }

                            // The magic marker is there so the framework is declared as supported, but no actual files are listed
                            // So we don't want to add a magic marker as a real artifact that can be referenced.
                            if (fileName != magicNugetMarker)
                            {
                                assemblyToTargetFramework.Add(fileName, targetFramework);
                            }
                        }
                    }
                }
            }

            // For the refs without lib, copy them to refs.
            foreach (var kv in libs)
            {
                if (!refs.ContainsKey(kv.Key))
                {
                    refs.Add(kv.Key, kv.Value.ToArray());
                }
            }

            References = refs;
            Libraries  = libs;
            AssemblyToTargetFramework = assemblyToTargetFramework;
        }
Exemplo n.º 32
0
 /// <nodoc/>
 public bool ContainsModule(ModuleDescriptor module)
 {
     return(m_backingDictionary.ContainsKey(module));
 }