Exemplo n.º 1
0
        private static UpversionType AnalyzeInterface(InterfaceSpec oldInterfaceSpec, InterfaceSpec newInterfaceSpec)
        {
            UpversionType maxUpversionType = UpversionType.Patch;

            if (newInterfaceSpec == null)
            {
                // The new spec removed a publically facing class.
                return(UpversionType.Major);
            }

            UpversionType upversionType = NapackAnalyst.AnalyzeProperties(oldInterfaceSpec.Properties, newInterfaceSpec.Properties);

            if (upversionType == UpversionType.Major)
            {
                return(upversionType);
            }
            else if (upversionType == UpversionType.Minor)
            {
                maxUpversionType = UpversionType.Minor;
            }

            upversionType = NapackAnalyst.AnalyzeMethods(oldInterfaceSpec.Methods, newInterfaceSpec.Methods);
            if (upversionType == UpversionType.Major)
            {
                return(upversionType);
            }
            else if (upversionType == UpversionType.Minor)
            {
                maxUpversionType = UpversionType.Minor;
            }

            return(maxUpversionType);
        }
Exemplo n.º 2
0
        private static UpversionType AnalyzeClass(ClassSpec oldClassSpec, ClassSpec newClassSpec)
        {
            UpversionType maxUpversionType = UpversionType.Patch;

            if (newClassSpec == null)
            {
                // The new spec removed a publically facing class.
                return(UpversionType.Major);
            }

            // Check if any modifier changes force a major (breaking) change.
            if ((!oldClassSpec.IsAbstract && newClassSpec.IsAbstract) ||
                (oldClassSpec.IsStatic != newClassSpec.IsStatic) ||
                (!oldClassSpec.IsSealed && newClassSpec.IsSealed))
            {
                return(UpversionType.Major);
            }

            // Verify all old fields exist
            UpversionType upversionType = NapackAnalyst.AnalyzeFields(oldClassSpec.PublicFields, newClassSpec.PublicFields);

            if (upversionType == UpversionType.Major)
            {
                return(upversionType);
            }
            else if (upversionType == UpversionType.Minor)
            {
                maxUpversionType = UpversionType.Minor;
            }

            upversionType = NapackAnalyst.AnalyzeProperties(oldClassSpec.PublicProperties, newClassSpec.PublicProperties);
            if (upversionType == UpversionType.Major)
            {
                return(upversionType);
            }
            else if (upversionType == UpversionType.Minor)
            {
                maxUpversionType = UpversionType.Minor;
            }

            upversionType = NapackAnalyst.AnalyzeConstructors(oldClassSpec.PublicConstructors, newClassSpec.PublicConstructors);
            if (upversionType == UpversionType.Major)
            {
                return(upversionType);
            }
            else if (upversionType == UpversionType.Minor)
            {
                maxUpversionType = UpversionType.Minor;
            }

            upversionType = NapackAnalyst.AnalyzeMethods(oldClassSpec.PublicMethods, newClassSpec.PublicMethods);
            if (upversionType == UpversionType.Major)
            {
                return(upversionType);
            }
            else if (upversionType == UpversionType.Minor)
            {
                maxUpversionType = UpversionType.Minor;
            }

            // Analyze classes recursively.
            foreach (ClassSpec oldClass in oldClassSpec.PublicClasses)
            {
                ClassSpec newClass = newClassSpec.PublicClasses
                                     .FirstOrDefault(cls => cls.Name.Name.Equals(oldClass.Name.Name, StringComparison.InvariantCulture));
                upversionType = NapackAnalyst.AnalyzeClass(oldClass, newClass);
                if (upversionType == UpversionType.Major)
                {
                    return(upversionType);
                }
                else if (upversionType == UpversionType.Minor)
                {
                    maxUpversionType = UpversionType.Minor;
                }
            }

            if (maxUpversionType == UpversionType.Patch && oldClassSpec.PublicClasses.Count != newClassSpec.PublicClasses.Count)
            {
                maxUpversionType = UpversionType.Minor;
            }

            return(maxUpversionType);
        }