Esempio n. 1
0
        /// <summary>
        /// Matches the modifier of the symbol with the access modifier of the candidates. Remove the candidates that do not match the modifier.
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <returns>True if there are any candidates left.</returns>
        protected IEnumerable <IBaseConfigModel> MatchModifier(ISymbol symbol, IEnumerable <IBaseConfigModel> candidates)
        {
            var matches = new List <IBaseConfigModel>();

            foreach (var candidate in candidates)
            {
                if (SymbolMatcher.MatchModifier(symbol, candidate.Modifier))
                {
                    matches.Add(candidate);
                }
            }

            return(matches);
        }
Esempio n. 2
0
        public void MatchModifierTest()
        {
            // Arrange
            var helpers        = new TestHelpers();
            var abstractMember = helpers.GetMockMember(Constants.AbstractMember, "TestMemberName");
            var overrideMember = helpers.GetMockMember(Constants.OverrideMember, "TestMemberName");
            var sealedMember   = helpers.GetMockMember(Constants.SealedMember, "TestMemberName");
            var staticMember   = helpers.GetMockMember(Constants.StaticMember, "TestMemberName");
            var virtualMember  = helpers.GetMockMember(Constants.VirtualMember, "TestMemberName");

            // Act
            var abstractMatch = SymbolMatcher.MatchModifier(abstractMember, Models.Modifier.Abstract);
            var overrideMatch = SymbolMatcher.MatchModifier(overrideMember, Models.Modifier.Override);
            var sealedMatch   = SymbolMatcher.MatchModifier(sealedMember, Models.Modifier.Sealed);
            var staticMatch   = SymbolMatcher.MatchModifier(staticMember, Models.Modifier.Static);
            var virtualMatch  = SymbolMatcher.MatchModifier(virtualMember, Models.Modifier.Virtual);

            var anyMatch = SymbolMatcher.MatchModifier(abstractMember, Models.Modifier.Any);

            var noAbstractMatch = SymbolMatcher.MatchModifier(abstractMember, Models.Modifier.Virtual);
            var noOverrideMatch = SymbolMatcher.MatchModifier(overrideMember, Models.Modifier.Abstract);
            var noSealedMatch   = SymbolMatcher.MatchModifier(sealedMember, Models.Modifier.Abstract);
            var noStaticMatch   = SymbolMatcher.MatchModifier(staticMember, Models.Modifier.Abstract);
            var noVirtualMatch  = SymbolMatcher.MatchModifier(virtualMember, Models.Modifier.Abstract);

            // Assert
            Assert.IsTrue(abstractMatch);
            Assert.IsTrue(overrideMatch);
            Assert.IsTrue(sealedMatch);
            Assert.IsTrue(staticMatch);
            Assert.IsTrue(virtualMatch);

            Assert.IsTrue(anyMatch);

            Assert.IsFalse(noAbstractMatch);
            Assert.IsFalse(noOverrideMatch);
            Assert.IsFalse(noSealedMatch);
            Assert.IsFalse(noStaticMatch);
            Assert.IsFalse(noVirtualMatch);
        }