Beispiel #1
0
        public static bool CompareAssemblies(StreamWriter writer, string sourceFile, string targetFile, IgnoreSet ignoreSet)
        {
            using (var source = ReadModule(sourceFile))
                using (var target = ReadModule(targetFile))
                {
                    writer.WriteLine($"## {Path.GetFileName(sourceFile)}");
                    var results = AssemblyComparer.CompareTypes(source, target);

                    return(ReportAnalyzer.GenerateReport(writer, results, ignoreSet));
                }
        }
        private static bool ReportMissingTypes(StreamWriter writer, ComparisonResult results, IgnoreSet ignoreSet)
        {
            var shouldFail = false;

            writer.WriteLine("### {0} missing types:", results.InvalidTypes.Length);
            foreach (var invalidType in results.InvalidTypes)
            {
                var isIgnored = ignoreSet.Types
                                .Select(t => t.FullName)
                                .Contains(invalidType.ToSignature());
                var strike = isIgnored
                                        ? "~~" : "";

                if (!isIgnored)
                {
                    Console.WriteLine($"Error : Removed type {invalidType.ToSignature()} not found in ignore set.");
                    shouldFail = true;
                }

                writer.WriteLine($"* {strike}`{invalidType.ToSignature()}`{strike}");
            }

            return(shouldFail);
        }
        private static bool ReportFields(StreamWriter writer, ComparisonResult results, IgnoreSet ignoreSet, string[] ignoredTypeNames)
        {
            var shouldFail = false;

            var groupedFields = from method in results.InvalidFields
                                group method by method.DeclaringType.FullName into types
                                select types;

            writer.WriteLine("### {0} missing or changed fields in existing types:", results.InvalidFields.Length);

            foreach (var updatedType in groupedFields)
            {
                writer.WriteLine("- `{0}`", updatedType.Key);
                foreach (var field in updatedType)
                {
                    var isIgnored = ignoreSet.Fields
                                    .Select(t => t.FullName)
                                    .Contains(field.ToSignature()) ||
                                    IsDeclaringTypeIgnored(field, ignoredTypeNames);

                    var strike = isIgnored
                                                ? "~~" : "";

                    if (!isIgnored)
                    {
                        Console.WriteLine($"Error : Removed field {field.ToSignature()} not found in ignore set.");
                        shouldFail = true;
                    }

                    writer.WriteLine($"\t* {strike}``{field.ToSignature()}``{strike}");
                }
            }

            return(shouldFail);
        }
        public static bool GenerateReport(StreamWriter writer, ComparisonResult results, IgnoreSet ignoreSet)
        {
            var ignoredTypeNames = ignoreSet?.Types.Select(t2 => t2.FullName).ToArray();
            var isFailed         = false;

            isFailed |= ReportMissingTypes(writer, results, ignoreSet);
            isFailed |= ReportMethods(writer, results, ignoreSet, ignoredTypeNames);
            isFailed |= ReportEvents(writer, results, ignoreSet, ignoredTypeNames);
            isFailed |= ReportFields(writer, results, ignoreSet, ignoredTypeNames);
            isFailed |= ReportProperties(writer, results, ignoreSet, ignoredTypeNames);

            return(isFailed);
        }