示例#1
0
        /// <summary>
        /// Matches the datatype of the symbol and the candidates
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <returns>True if there are candidates left</returns>
        private IEnumerable <IBaseConfigModel> MatchDataType(ISymbol symbol, IEnumerable <IBaseConfigModel> candidates)
        {
            var matches = new List <IBaseConfigModel>();

            foreach (Member member in candidates)
            {
                var typeMatch = true;

                if (member.DataType?.Custom == true && member.DataType.TypeName == ((Component)member.Parent).Name)
                {
                    // returns the parentname, can be checked
                    typeMatch = SymbolMatcher.MatchDataType(symbol, symbol.ContainingSymbol.Name);
                }
                else if (member.DataType?.Custom == false)
                {
                    typeMatch = SymbolMatcher.MatchDataType(symbol, member.DataType.Type.Name);
                }
                else
                {
                    // Not able to determine the correct type at this time
                }

                if (member.DataType != null)
                {
                    typeMatch &= SymbolMatcher.MatchCollection(symbol, member.DataType.Collection);
                }

                if (typeMatch)
                {
                    matches.Add(member);
                }
            }

            return(matches);
        }
        public void MatchDataTypeTest()
        {
            // Arrange
            var helpers = new TestHelpers();

            var fieldMember     = helpers.GetMockMember(Constants.PrivateFieldMember, "TestMemberName");
            var methodMember    = helpers.GetMockMember(Constants.PublicMethodMember, "TestMemberName");
            var namedTypeMember = helpers.GetMockMember(Constants.PublicNamedTypeMember, "TestMemberName");
            var propertyMember  = helpers.GetMockMember(Constants.PublicPropertyMember, "TestMemberName");
            var eventMember     = helpers.GetMockMember(Constants.PublicEventMember, "TestMemberName");

            // Act
            var fieldMatch     = SymbolMatcher.MatchDataType(fieldMember, "String");
            var methodMatch    = SymbolMatcher.MatchDataType(methodMember, "Void");
            var namedTypeMatch = SymbolMatcher.MatchDataType(namedTypeMember, "TestMemberName");
            var propertyMatch  = SymbolMatcher.MatchDataType(propertyMember, "String");
            var eventMatch     = SymbolMatcher.MatchDataType(eventMember, "DelegateMember");

            var anyMatch = SymbolMatcher.MatchDataType(fieldMember, string.Empty);

            var noFieldMatch     = SymbolMatcher.MatchDataType(fieldMember, "wrong");
            var noMethodMatch    = SymbolMatcher.MatchDataType(methodMember, "wrong");
            var noNamedTypeMatch = SymbolMatcher.MatchDataType(namedTypeMember, "wrong");
            var noPropertyMatch  = SymbolMatcher.MatchDataType(propertyMember, "wrong");
            var noEventMatch     = SymbolMatcher.MatchDataType(eventMember, "wrong");

            // Assert
            Assert.IsTrue(fieldMatch);
            Assert.IsTrue(methodMatch);
            Assert.IsTrue(namedTypeMatch);
            Assert.IsTrue(propertyMatch);
            Assert.IsTrue(eventMatch);

            Assert.IsTrue(anyMatch);

            Assert.IsFalse(noFieldMatch);
            Assert.IsFalse(noMethodMatch);
            Assert.IsFalse(noNamedTypeMatch);
            Assert.IsFalse(noPropertyMatch);
            Assert.IsFalse(noEventMatch);
        }