Exemplo n.º 1
0
        public void Test_Dictionary_SuccessfulAdd()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string>();

            dictionary.Add(1, "one");
            dictionary.Add(1, "ich");
            Assert.AreEqual(true, dictionary.Contains(1, "one"));
            Assert.AreEqual(true, dictionary.Contains(1, "ich"));
        }
Exemplo n.º 2
0
        public void Test_Dictionary_RemoveValue()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string> {
                { 1, "one" }, { 1, "ich" }
            };

            dictionary.Remove(1, "one");
            Assert.AreEqual(true, dictionary.Contains(1, "ich"));
            Assert.AreEqual(false, dictionary.Contains(1, "one"));
        }
Exemplo n.º 3
0
        public void Test_Contains_Failure()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 3, "sun" }, { 1, "two" }, { 3, "three" }
            };

            Assert.AreEqual(false, dictionary.Contains(2, "two"));
            Assert.AreEqual(false, dictionary.Contains(1, "nee"));
            Assert.AreEqual(false, dictionary.Contains(4, "four"));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 加入组播
        /// </summary>
        /// <param name="multicastAddress"></param>
        /// <param name="session"></param>
        public bool Join(string multicastAddress, IServerSession session)
        {
            lock (_multicastSessions)
            {
                if (_reverseMulticastSessions.Contains(session, multicastAddress))
                {
                    return(false);
                }

                _multicastSessions.Add(multicastAddress, session);
                _reverseMulticastSessions.Add(session, multicastAddress);
            }
            return(true);
        }
Exemplo n.º 5
0
        public void Test_Contains()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 3, "sun" }, { 2, "two" }, { 3, "three" }
            };

            Assert.AreEqual(true, dictionary.Contains(2, "two"));
        }
Exemplo n.º 6
0
        public void Test_Dictionary_SuccessfulContainCheck()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string> {
                { 1, "one" }
            };

            Assert.AreEqual(true, dictionary.Contains(1, "one"));
        }
Exemplo n.º 7
0
        public void Test_Add_First_Key_To_Empty_Dictionary()
        {
            var dictionary = new MultiDictionary <int, string>();

            Assert.AreEqual(0, dictionary.Count);
            dictionary.Add(1, "one");
            Assert.AreEqual(true, dictionary.Contains(1, "one"));
            Assert.AreEqual(1, dictionary.Count);
        }
Exemplo n.º 8
0
        public void ContainPass()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string>
            {
                { 2, "three" },
                { 1, "three" }
            };

            Assert.AreEqual(true, dictionary.Contains(1, "three"));
        }
Exemplo n.º 9
0
        public void ContainFail()
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string>
            {
                { 2, "three" },
                { 1, "three" }
            };

            Assert.AreEqual(false, dictionary.Contains(3, "three"));
        }
Exemplo n.º 10
0
        public void Test_Add_To_Existing_Key()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 1, "one" }, { 2, "two" }
            };

            Assert.AreEqual(2, dictionary.Count);
            dictionary.Add(1, "ich");
            Assert.AreEqual(true, dictionary.Contains(1, "ich"));
            Assert.AreEqual(3, dictionary.Count);
        }
Exemplo n.º 11
0
 //cheks if the dictionary contains the given item
 public bool Contains(KeyValuePair <TKey, HashSet <TValue> > item)
 {
     if (MultiDictionary.Contains(item))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        ///Contains 的测试
        ///</summary>
        public void ContainsTest1Helper <KeyT, ValueT>()
        {
            bool allowDuplicateValues = false;                                                                            // TODO: 初始化为适当的值
            MultiDictionary <KeyT, ValueT>             target = new MultiDictionary <KeyT, ValueT>(allowDuplicateValues); // TODO: 初始化为适当的值
            KeyValuePair <KeyT, ICollection <ValueT> > pair   = new KeyValuePair <KeyT, ICollection <ValueT> >();         // TODO: 初始化为适当的值
            bool expected = false;                                                                                        // TODO: 初始化为适当的值
            bool actual;

            actual = target.Contains(pair);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Contains(KeyT key, ValueT value)
        {
            bool bReturn = false;

            m_LockMultiDictionary.EnterReadLock();
            {
                bReturn = m_MultiDictionary.Contains(key, value);
            }
            m_LockMultiDictionary.ExitReadLock();

            return(bReturn);
        }
Exemplo n.º 14
0
        /// <summary>
        ///Contains 的测试
        ///</summary>
        public void ContainsTestHelper <KeyT, ValueT>()
        {
            bool allowDuplicateValues             = false;                                                    // TODO: 初始化为适当的值
            MultiDictionary <KeyT, ValueT> target = new MultiDictionary <KeyT, ValueT>(allowDuplicateValues); // TODO: 初始化为适当的值
            KeyT   key      = default(KeyT);                                                                  // TODO: 初始化为适当的值
            ValueT value    = default(ValueT);                                                                // TODO: 初始化为适当的值
            bool   expected = false;                                                                          // TODO: 初始化为适当的值
            bool   actual;

            actual = target.Contains(key, value);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Exemplo n.º 15
0
        public void Test_Add_New_Key()
        {
            var dictionary = new MultiDictionary <int, string> {
                { 1, "one" }, { 2, "two" }
            };

            Assert.AreEqual(2, dictionary.Count);
            Assert.AreEqual(false, dictionary.ContainsKey(3));
            dictionary.Add(3, "sun");
            Assert.AreEqual(true, dictionary.ContainsKey(3));
            Assert.AreEqual(true, dictionary.Contains(3, "sun"));
            Assert.AreEqual(3, dictionary.Count);
        }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool ContainsValue(KeyT key, ValueT value)
 {
     return(m_MultiDictionary.Contains(key, value));
 }
Exemplo n.º 17
0
        private static Symbol FindExplicitlyImplementedMember(
            Symbol implementingMember,
            TypeSymbol explicitInterfaceType,
            string interfaceMemberName,
            ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifierSyntax,
            DiagnosticBag diagnostics)
        {
            if ((object)explicitInterfaceType == null)
            {
                return(null);
            }

            var memberLocation = implementingMember.Locations[0];
            var containingType = implementingMember.ContainingType;

            switch (containingType.TypeKind)
            {
            case TypeKind.Class:
            case TypeKind.Struct:
            case TypeKind.Interface:
                break;

            default:
                diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationInNonClassOrStruct, memberLocation, implementingMember);
                return(null);
            }

            if (!explicitInterfaceType.IsInterfaceType())
            {
                //we'd like to highlight just the type part of the name
                var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name;
                var location = new SourceLocation(explicitInterfaceSyntax);

                diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationNotInterface, location, explicitInterfaceType);
                return(null);
            }

            var explicitInterfaceNamedType = (NamedTypeSymbol)explicitInterfaceType;

            // 13.4.1: "For an explicit interface member implementation to be valid, the class or struct must name an
            // interface in its base class list that contains a member ..."
            MultiDictionary <NamedTypeSymbol, NamedTypeSymbol> .ValueSet set = containingType.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics[explicitInterfaceNamedType];
            int setCount = set.Count;

            if (setCount == 0 || !set.Contains(explicitInterfaceNamedType, Symbols.SymbolEqualityComparer.ObliviousNullableModifierMatchesAny))
            {
                //we'd like to highlight just the type part of the name
                var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name;
                var location = new SourceLocation(explicitInterfaceSyntax);

                if (setCount > 0 && set.Contains(explicitInterfaceNamedType, Symbols.SymbolEqualityComparer.IgnoringNullable))
                {
                    diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInExplicitlyImplementedInterface, location);
                }
                else
                {
                    diagnostics.Add(ErrorCode.ERR_ClassDoesntImplementInterface, location, implementingMember, explicitInterfaceNamedType);
                }

                //do a lookup anyway
            }

            // Do not look in itself
            if (containingType == (object)explicitInterfaceNamedType.OriginalDefinition)
            {
                // An error will be reported elsewhere.
                // Either the interface is not implemented, or it causes a cycle in the interface hierarchy.
                return(null);
            }

            var hasParamsParam = implementingMember.HasParamsParameter();

            // Setting this flag to true does not imply that an interface member has been successfully implemented.
            // It just indicates that a corresponding interface member has been found (there may still be errors).
            var foundMatchingMember = false;

            Symbol implementedMember = null;

            foreach (Symbol interfaceMember in explicitInterfaceNamedType.GetMembers(interfaceMemberName))
            {
                // At this point, we know that explicitInterfaceNamedType is an interface.
                // However, metadata interface members can be static - we ignore them, as does Dev10.
                if (interfaceMember.Kind != implementingMember.Kind || !interfaceMember.IsImplementableInterfaceMember())
                {
                    continue;
                }

                if (MemberSignatureComparer.ExplicitImplementationComparer.Equals(implementingMember, interfaceMember))
                {
                    foundMatchingMember = true;
                    // Cannot implement accessor directly unless
                    // the accessor is from an indexed property.
                    if (interfaceMember.IsAccessor() && !((MethodSymbol)interfaceMember).IsIndexedPropertyAccessor())
                    {
                        diagnostics.Add(ErrorCode.ERR_ExplicitMethodImplAccessor, memberLocation, implementingMember, interfaceMember);
                    }
                    else
                    {
                        if (interfaceMember.MustCallMethodsDirectly())
                        {
                            diagnostics.Add(ErrorCode.ERR_BogusExplicitImpl, memberLocation, implementingMember, interfaceMember);
                        }
                        else if (hasParamsParam && !interfaceMember.HasParamsParameter())
                        {
                            // Note: no error for !hasParamsParam && interfaceMethod.HasParamsParameter()
                            // Still counts as an implementation.
                            diagnostics.Add(ErrorCode.ERR_ExplicitImplParams, memberLocation, implementingMember, interfaceMember);
                        }

                        implementedMember = interfaceMember;
                        break;
                    }
                }
            }

            if (!foundMatchingMember)
            {
                // CONSIDER: we may wish to suppress this error in the event that another error
                // has been reported about the signature.
                diagnostics.Add(ErrorCode.ERR_InterfaceMemberNotFound, memberLocation, implementingMember);
            }

            // Make sure implemented member is accessible
            if ((object)implementedMember != null)
            {
                HashSet <DiagnosticInfo> useSiteDiagnostics = null;

                if (!AccessCheck.IsSymbolAccessible(implementedMember, implementingMember.ContainingType, ref useSiteDiagnostics, throughTypeOpt: null))
                {
                    diagnostics.Add(ErrorCode.ERR_BadAccess, memberLocation, implementedMember);
                }
                else
                {
                    switch (implementedMember.Kind)
                    {
                    case SymbolKind.Property:
                        var propertySymbol = (PropertySymbol)implementedMember;
                        checkAccessorIsAccessibleIfImplementable(propertySymbol.GetMethod);
                        checkAccessorIsAccessibleIfImplementable(propertySymbol.SetMethod);
                        break;

                    case SymbolKind.Event:
                        var eventSymbol = (EventSymbol)implementedMember;
                        checkAccessorIsAccessibleIfImplementable(eventSymbol.AddMethod);
                        checkAccessorIsAccessibleIfImplementable(eventSymbol.RemoveMethod);
                        break;
                    }

                    void checkAccessorIsAccessibleIfImplementable(MethodSymbol accessor)
                    {
                        if (accessor.IsImplementable() &&
                            !AccessCheck.IsSymbolAccessible(accessor, implementingMember.ContainingType, ref useSiteDiagnostics, throughTypeOpt: null))
                        {
                            diagnostics.Add(ErrorCode.ERR_BadAccess, memberLocation, accessor);
                        }
                    }
                }

                diagnostics.Add(memberLocation, useSiteDiagnostics);
            }

            return(implementedMember);
        }
Exemplo n.º 18
0
        private static Symbol FindExplicitlyImplementedMember(
            Symbol implementingMember,
            TypeSymbol explicitInterfaceType,
            string interfaceMemberName,
            ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifierSyntax,
            DiagnosticBag diagnostics)
        {
            if ((object)explicitInterfaceType == null)
            {
                return(null);
            }

            var memberLocation     = implementingMember.Locations[0];
            var containingType     = implementingMember.ContainingType;
            var containingTypeKind = containingType.TypeKind;

            if (containingTypeKind != TypeKind.Class && containingTypeKind != TypeKind.Struct)
            {
                diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationInNonClassOrStruct, memberLocation, implementingMember);
                return(null);
            }

            if (!explicitInterfaceType.IsInterfaceType())
            {
                //we'd like to highlight just the type part of the name
                var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name;
                var location = new SourceLocation(explicitInterfaceSyntax);

                diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationNotInterface, location, explicitInterfaceType);
                return(null);
            }

            var explicitInterfaceNamedType = (NamedTypeSymbol)explicitInterfaceType;

            // 13.4.1: "For an explicit interface member implementation to be valid, the class or struct must name an
            // interface in its base class list that contains a member ..."
            MultiDictionary <NamedTypeSymbol, NamedTypeSymbol> .ValueSet set = containingType.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics[explicitInterfaceNamedType];
            int setCount = set.Count;

            if (setCount == 0 || !set.Contains(explicitInterfaceNamedType))
            {
                //we'd like to highlight just the type part of the name
                var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name;
                var location = new SourceLocation(explicitInterfaceSyntax);

                if (setCount > 0 && set.Contains(explicitInterfaceNamedType, TypeSymbol.EqualsIgnoringNullableComparer))
                {
                    diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInExplicitlyImplementedInterface, location);
                }
                else
                {
                    diagnostics.Add(ErrorCode.ERR_ClassDoesntImplementInterface, location, implementingMember, explicitInterfaceNamedType);
                }

                //do a lookup anyway
            }

            var hasParamsParam = implementingMember.HasParamsParameter();

            // Setting this flag to true does not imply that an interface member has been successfully implemented.
            // It just indicates that a corresponding interface member has been found (there may still be errors).
            var foundMatchingMember = false;

            Symbol implementedMember = null;

            foreach (Symbol interfaceMember in explicitInterfaceNamedType.GetMembers(interfaceMemberName))
            {
                // At this point, we know that explicitInterfaceNamedType is an interface, so candidate must be public
                // and, therefore, accessible.  So we don't need to check that.
                // However, metadata interface members can be static - we ignore them, as does Dev10.
                if (interfaceMember.Kind != implementingMember.Kind || interfaceMember.IsStatic)
                {
                    continue;
                }

                if (MemberSignatureComparer.ExplicitImplementationLookupComparer.Equals(implementingMember, interfaceMember))
                {
                    foundMatchingMember = true;
                    // Cannot implement accessor directly unless
                    // the accessor is from an indexed property.
                    if (interfaceMember.IsAccessor() && !((MethodSymbol)interfaceMember).IsIndexedPropertyAccessor())
                    {
                        diagnostics.Add(ErrorCode.ERR_ExplicitMethodImplAccessor, memberLocation, implementingMember, interfaceMember);
                    }
                    else
                    {
                        if (interfaceMember.MustCallMethodsDirectly())
                        {
                            diagnostics.Add(ErrorCode.ERR_BogusExplicitImpl, memberLocation, implementingMember, interfaceMember);
                        }
                        else if (hasParamsParam && !interfaceMember.HasParamsParameter())
                        {
                            // Note: no error for !hasParamsParam && interfaceMethod.HasParamsParameter()
                            // Still counts as an implementation.
                            diagnostics.Add(ErrorCode.ERR_ExplicitImplParams, memberLocation, implementingMember, interfaceMember);
                        }

                        implementedMember = interfaceMember;
                        break;
                    }
                }
            }

            if (!foundMatchingMember)
            {
                // CONSIDER: we may wish to suppress this error in the event that another error
                // has been reported about the signature.
                diagnostics.Add(ErrorCode.ERR_InterfaceMemberNotFound, memberLocation, implementingMember);
            }

            return(implementedMember);
        }