예제 #1
0
        private static MethodInfo GetMissingExtensionMethod(Type a, Type b, IEnumerable <string> excludedMethods)
        {
            var dex = new HashSet <string>(excludedMethods);

            var aMethods =
                a.GetMethods(BindingFlags.Static | BindingFlags.Public)
                .Where(m => m.CustomAttributes.Any(c => c.AttributeType == typeof(ExtensionAttribute)))
                .ToLookup(m => m.Name);

            MethodComparer mc       = new MethodComparer();
            var            bMethods = b.GetMethods(BindingFlags.Static | BindingFlags.Public)
                                      .Where(m => m.CustomAttributes.Any(c => c.AttributeType == typeof(ExtensionAttribute)))
                                      .ToLookup(m => m, mc);

            foreach (var group in aMethods.Where(g => !dex.Contains(g.Key)))
            {
                foreach (MethodInfo m in group)
                {
                    if (!bMethods.Contains(m))
                    {
                        return(m);
                    }
                }
            }

            return(null);
        }
        public IMetadataDiffItem <MethodDefinition> GenerateAccessorDiffItem()
        {
            MethodDefinition oldAccessor = SelectAccessor(this.oldElement);
            MethodDefinition newAccessor = SelectAccessor(this.newElement);

            if (oldAccessor == null && newAccessor == null)
            {
                return(null);
            }

            if (oldAccessor == null && newAccessor != null ||
                oldAccessor != null && newAccessor == null)
            {
                return((oldAccessor ?? newAccessor).IsAPIDefinition() ? CreateAccessorDiffItem(null) : null);
            }

            if (!oldAccessor.IsAPIDefinition() && !newAccessor.IsAPIDefinition())
            {
                return(null);
            }

            IEnumerable <IDiffItem> declarationDiffs = new MethodComparer().GetDeclarationDiffs(oldAccessor, newAccessor).Where(item => !(item is MemberTypeDiffItem));

            if (declarationDiffs.IsEmpty())
            {
                return(null);
            }

            return(CreateAccessorDiffItem(declarationDiffs));
        }
예제 #3
0
        public static IChangeCalculator BuildCalculator(ILogger?logger)
        {
            var attributeComparer  = new AttributeComparer();
            var attributeMatcher   = new AttributeEvaluator();
            var attributeProcessor = new AttributeMatchProcessor(attributeMatcher, attributeComparer, logger);

            var accessModifierChangeTable  = new AccessModifiersChangeTable();
            var accessModifiersComparer    = new AccessModifiersComparer(accessModifierChangeTable);
            var memberModifiersChangeTable = new PropertyModifiersChangeTable();
            var memberModifiersComparer    = new PropertyModifiersComparer(memberModifiersChangeTable);

            var genericTypeElementComparer = new GenericTypeElementComparer();

            var fieldModifiersChangeTable = new FieldModifiersChangeTable();
            var fieldModifiersComparer    = new FieldModifiersComparer(fieldModifiersChangeTable);
            var fieldComparer             = new FieldComparer(accessModifiersComparer, fieldModifiersComparer, attributeProcessor);
            var fieldMatcher   = new FieldEvaluator();
            var fieldProcessor = new FieldMatchProcessor(fieldMatcher, fieldComparer, logger);

            var propertyAccessorAccessModifiersChangeTable = new PropertyAccessorAccessModifiersChangeTable();
            var propertyAccessorAccessModifiersComparer    = new PropertyAccessorAccessModifiersComparer(propertyAccessorAccessModifiersChangeTable);
            var propertyAccessorComparer  = new PropertyAccessorComparer(propertyAccessorAccessModifiersComparer, attributeProcessor);
            var propertyAccessorEvaluator = new PropertyAccessorEvaluator();
            var propertyAccessorProcessor =
                new PropertyAccessorMatchProcessor(propertyAccessorEvaluator, propertyAccessorComparer, logger);
            var propertyComparer  = new PropertyComparer(accessModifiersComparer, memberModifiersComparer, propertyAccessorProcessor, attributeProcessor);
            var propertyMatcher   = new PropertyEvaluator();
            var propertyProcessor = new PropertyMatchProcessor(propertyMatcher, propertyComparer, logger);

            var methodEvaluator               = new MethodEvaluator();
            var methodModifiersChangeTable    = new MethodModifiersChangeTable();
            var methodModifiersComparer       = new MethodModifiersComparer(methodModifiersChangeTable);
            var parameterModifiersChangeTable = new ParameterModifiersChangeTable();
            var parameterModifiersComparer    = new ParameterModifiersComparer(parameterModifiersChangeTable);
            var parameterComparer             = new ParameterComparer(parameterModifiersComparer, attributeProcessor);
            var methodComparer  = new MethodComparer(accessModifiersComparer, methodModifiersComparer, genericTypeElementComparer, parameterComparer, attributeProcessor);
            var methodProcessor = new MethodMatchProcessor(methodEvaluator, methodComparer, logger);

            var classModifiersChangeTable = new ClassModifiersChangeTable();
            var classModifiersComparer    = new ClassModifiersComparer(classModifiersChangeTable);
            var classComparer             = new ClassComparer(
                accessModifiersComparer,
                classModifiersComparer,
                genericTypeElementComparer,
                fieldProcessor,
                propertyProcessor,
                methodProcessor, attributeProcessor);

            var interfaceComparer = new InterfaceComparer(
                accessModifiersComparer,
                genericTypeElementComparer,
                propertyProcessor,
                methodProcessor,
                attributeProcessor);

            var structModifiersChangeTable = new StructModifiersChangeTable();
            var structModifiersComparer    = new StructModifiersComparer(structModifiersChangeTable);
            var structComparer             = new StructComparer(
                accessModifiersComparer,
                structModifiersComparer,
                genericTypeElementComparer,
                fieldProcessor,
                propertyProcessor,
                methodProcessor,
                attributeProcessor);

            var aggregateTypeComparer = new AggregateTypeComparer(classComparer, interfaceComparer, structComparer);

            var typeEvaluator = new TypeEvaluator();
            var typeProcessor = new TypeMatchProcessor(typeEvaluator, aggregateTypeComparer, logger);

            return(new ChangeCalculator(typeProcessor, logger));
        }