/// <summary>
        ///     Checks if the type has changes
        ///     On type level
        ///     Base Types, implemented interfaces, generic parameters
        ///     On method level
        ///     Method modifiers, return type, generic parameters, parameter count, parameter types (also generics)
        ///     On field level
        ///     Field types
        /// </summary>
        /// <param name="typeV1">The type v1.</param>
        /// <param name="typeV2">The type v2.</param>
        /// <param name="diffQueries">The diff queries.</param>
        /// <returns></returns>
        public static TypeDiff GenerateDiff(TypeDefinition typeV1, TypeDefinition typeV2, QueryAggregator diffQueries)
        {
            if (typeV1 == null)
            {
                throw new ArgumentNullException("typeV1");
            }
            if (typeV2 == null)
            {
                throw new ArgumentNullException("typeV2");
            }
            if (diffQueries == null || diffQueries.FieldQueries.Count == 0 || diffQueries.MethodQueries.Count == 0)
            {
                throw new ArgumentException("diffQueries was null or the method or field query list was emtpy. This will not result in a meaningful diff result");
            }

            var diff = new TypeDiff(typeV1, typeV2);

            diff.DoDiff(diffQueries);

            if (!diff.HasChangedBaseType && diff.Events.Count == 0 && diff.Fields.Count == 0 && diff.Interfaces.Count == 0 && diff.Methods.Count == 0)
            {
                return(None);
            }

            return(diff);
        }
        private void PrintTypeChanges(TypeDiff typeChange)
        {
            this.Out.WriteLine("\t" + typeChange.TypeV1.Print());
            if (typeChange.HasChangedBaseType)
            {
                this.Out.WriteLine("\t\tBase type changed: {0} -> {1}", typeChange.TypeV1.IsNotNull(() => typeChange.TypeV1.BaseType.IsNotNull(() => typeChange.TypeV1.BaseType.FullName)), typeChange.TypeV2.IsNotNull(() => typeChange.TypeV2.BaseType.IsNotNull(() => typeChange.TypeV2.BaseType.FullName)));
            }

            if (typeChange.Interfaces.Count > 0)
            {
                foreach (var addedItf in typeChange.Interfaces.Added)
                {
                    this.Out.WriteLine("\t\t+ interface: {0}", addedItf.ObjectV1.FullName);
                }
                foreach (var removedItd in typeChange.Interfaces.Removed)
                {
                    this.Out.WriteLine("\t\t- interface: {0}", removedItd.ObjectV1.FullName);
                }
            }

            foreach (var addedEvent in typeChange.Events.Added)
            {
                this.Out.WriteLine("\t\t+ {0}", addedEvent.ObjectV1.Print());
            }

            foreach (var remEvent in typeChange.Events.Removed)
            {
                this.Out.WriteLine("\t\t- {0}", remEvent.ObjectV1.Print());
            }

            foreach (var addedField in typeChange.Fields.Added)
            {
                this.Out.WriteLine("\t\t+ {0}", addedField.ObjectV1.Print(FieldPrintOptions.All));
            }

            foreach (var remField in typeChange.Fields.Removed)
            {
                this.Out.WriteLine("\t\t- {0}", remField.ObjectV1.Print(FieldPrintOptions.All));
            }

            foreach (var addedMethod in typeChange.Methods.Added)
            {
                this.Out.WriteLine("\t\t+ {0}", addedMethod.ObjectV1.Print(MethodPrintOption.Full));
            }

            foreach (var remMethod in typeChange.Methods.Removed)
            {
                this.Out.WriteLine("\t\t- {0}", remMethod.ObjectV1.Print(MethodPrintOption.Full));
            }
        }
Beispiel #3
0
        private void DiffTypes(List <TypeDefinition> typesV1, List <TypeDefinition> typesV2, QueryAggregator queries)
        {
            TypeDefinition typeV2;

            foreach (var typeV1 in typesV1)
            {
                typeV2 = this.GetTypeByDefinition(typeV1, typesV2);
                if (typeV2 != null)
                {
                    var diffed = TypeDiff.GenerateDiff(typeV1, typeV2, queries);
                    if (TypeDiff.None != diffed)
                    {
                        this.myDiff.ChangedTypes.Add(diffed);
                    }
                }
            }
        }
        private void CheckFieldChanges(TypeDiff changedType)
        {
            var removedFields = changedType.Fields.RemovedList;

            if (removedFields.Count > 0)
            {
                var nonConstFields = (from field in removedFields where !field.HasConstant select field).ToList();

                new WhoAccessesField(this.myAggregator, nonConstFields);

                foreach (var field in changedType.Fields.Removed)
                {
                    if (field.ObjectV1.HasConstant)
                    {
                        Console.WriteLine("Warning: Constants are not referenced by other assemblies but copied by value: field {0} declaring type {1} in assembly {2}", field.ObjectV1.Print(FieldPrintOptions.All), field.ObjectV1.DeclaringType.Name, field.ObjectV1.DeclaringType.Module.Assembly.Name.Name);
                        new WhoUsesType(this.myAggregator, changedType.TypeV1);
                    }
                }
            }
        }
        private void AddIntefaceChange(TypeDiff changedType)
        {
            // A changed interface breaks all its implementers
            new WhoImplementsInterface(this.myAggregator, changedType.TypeV1);

            // If methods are removed we must also search for all users of this
            // interface method
            var removedInterfaceMethods = changedType.Methods.RemovedList;

            if (removedInterfaceMethods.Count > 0)
            {
                new WhoUsesMethod(this.myAggregator, removedInterfaceMethods);
            }

            var removedInterfaceEvents = changedType.Events.RemovedList;

            if (removedInterfaceEvents.Count > 0)
            {
                new WhoUsesEvents(this.myAggregator, removedInterfaceEvents);
            }
        }