From d36f2d7405889ec0334735a6c0a4287079349436 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Fri, 25 Mar 2022 16:46:08 -0700 Subject: [PATCH 1/8] Split "HighlighBaseMembers" into "HighlightMemberOverrides" and "HighlightInterfaceImplementations". Update Readme to reflect this. Add extra boolean checks for the newly split options. --- .../DiffCSharpWriter.cs | 8 +++++--- .../DiffConfiguration.cs | 3 ++- .../DiffConfigurationOptions.cs | 7 +++++-- src/Microsoft.DotNet.AsmDiff/DiffEngine.cs | 15 +++++++++------ src/Microsoft.DotNet.AsmDiff/Program.cs | 19 +++++++++++++++++-- src/Microsoft.DotNet.AsmDiff/README.md | 2 ++ 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs index d9dc5bbeb30..cb5a08c87fb 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs @@ -51,14 +51,16 @@ public DiffCSharpWriter(IStyleSyntaxWriter writer, MappingSettings settings, IEn public DiffCSharpWriter(IStyleSyntaxWriter writer, MappingSettings settings) : this(writer, settings, null, false) - { + { } public bool IncludeSpaceBetweenMemberGroups { get; set; } public bool IncludeMemberGroupHeadings { get; set; } - public bool HighlightBaseMembers { get; set; } + public bool HighlightMemberOverrides { get; set; } + + public bool HighlightInterfaceImplementations { get; set; } public bool IncludeAssemblyProperties { get; set; } @@ -237,7 +239,7 @@ private void WriteComments(ElementMapping mapping) where TEl foreach (var comment in commentSet) { reviewCommentWriter.WriteReviewComment(comment.Author, comment.Text); - _syntaxWriter.WriteLine(); + _syntaxWriter.WriteLine(); } } } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs b/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs index aa2999889e1..808aaef5ec3 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs @@ -15,7 +15,8 @@ public DiffConfiguration() DiffConfigurationOptions.IncludeUnchanged | DiffConfigurationOptions.IncludeAddedTypes | DiffConfigurationOptions.IncludeRemovedTypes | - DiffConfigurationOptions.HighlightBaseMembers; + DiffConfigurationOptions.HightlightMemberOverrides | + DiffConfigurationOptions.HighlightInterfaceImplementations; } public DiffConfiguration(AssemblySet left, AssemblySet right, DiffConfigurationOptions options) diff --git a/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs b/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs index 3a3d5588e9a..cf07c404545 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs @@ -21,10 +21,13 @@ public enum DiffConfigurationOptions GroupByAssembly = 0x400, FlattenTypes = 0x800, TypesOnly = 0x1000, - HighlightBaseMembers = 0x2000, AlwaysDiffMembers = 0x4000, IncludeAddedTypes = 0x8000, IncludeRemovedTypes = 0x10000, - StrikeRemoved = 0x20000 + StrikeRemoved = 0x20000, + HightlightMemberOverrides = 0x40000, + HighlightInterfaceImplementations = 0x80000, + + HighlightBasesMembers = HightlightMemberOverrides | HighlightInterfaceImplementations, } } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs b/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs index 7287760e832..b9c17e2fe7a 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs @@ -60,16 +60,18 @@ private static ICciDifferenceWriter CreateExportWriter(DiffFormat format, TextWr return new DiffCSharpWriter(writer, mappingSettings, diffComments, includeAttributes) { IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), - HighlightBaseMembers = configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers) + HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), }; case DiffFormat.WordXml: case DiffFormat.Text: case DiffFormat.UnifiedDiff: return new DiffCSharpWriter(writer, mappingSettings, diffComments, includeAttributes) - { - IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), - HighlightBaseMembers = configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers) - }; + { + IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), + HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + }; default: throw new ArgumentOutOfRangeException("format"); } @@ -164,7 +166,8 @@ private static void GetTokens(DiffConfiguration configuration, CancellationToken var writer = new ApiRecordingCSharpDiffWriter(diffRecorder, mappingSettings, includeAttributes) { IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), - HighlightBaseMembers = configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers) + HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), }; WriteDiff(configuration, writer); diff --git a/src/Microsoft.DotNet.AsmDiff/Program.cs b/src/Microsoft.DotNet.AsmDiff/Program.cs index 5ae9aecf52e..2155613de1a 100644 --- a/src/Microsoft.DotNet.AsmDiff/Program.cs +++ b/src/Microsoft.DotNet.AsmDiff/Program.cs @@ -42,6 +42,10 @@ public class Program public bool AlwaysDiffMembers { get; set; } [Option("-hbm|--HighlightBaseMembers", "Highlight members that are interface implementations or overrides of a base member.", CommandOptionType.NoValue)] public bool HighlightBaseMembers { get; set; } + [Option("-hmo|--HighlightMemberOverrides", "Highlight members that are overrides of a base member.", CommandOptionType.NoValue)] + public bool HighlightMemberOverrides { get; set; } + [Option("-hii|--HighlightInterfaceImplementations", "Highlight members that are explicit interface implementations.", CommandOptionType.NoValue)] + public bool HighlightInterfaceImplementations { get; set; } [Option("-ft|--FlattenTypes", "Will flatten types so that all members available on the type show on the type not just the implemented ones.", CommandOptionType.NoValue)] public bool FlattenTypes { get; set; } @@ -54,7 +58,7 @@ public class Program [Option("-iia|--IncludeInternalApis", "Include internal types and members as part of the diff.", CommandOptionType.NoValue)] public bool IncludeInternalApis { get; set; } [Option("-ipa|--IncludePrivateApis", "Include private types and members as part of the diff.", CommandOptionType.NoValue)] - public bool IncludePrivateApis { get; set; } + public bool IncludePrivateApis { get; set; } [Option("-itc|--IncludeTableOfContents", "Include table of contents as part of the diff.", CommandOptionType.NoValue)] public bool IncludeTableOfContents { get; set; } @@ -147,7 +151,18 @@ private DiffConfigurationOptions GetDiffOptions() result |= DiffConfigurationOptions.GroupByAssembly; if (HighlightBaseMembers) - result |= DiffConfigurationOptions.HighlightBaseMembers; + { + result |= DiffConfigurationOptions.HightlightMemberOverrides; + result |= DiffConfigurationOptions.HighlightInterfaceImplementations; + } + else + { + if (HighlightMemberOverrides) + result |= DiffConfigurationOptions.HightlightMemberOverrides; + + if (HighlightInterfaceImplementations) + result |= DiffConfigurationOptions.HighlightInterfaceImplementations; + } if (DiffAssemblyInfo) result |= DiffConfigurationOptions.DiffAssemblyInfo; diff --git a/src/Microsoft.DotNet.AsmDiff/README.md b/src/Microsoft.DotNet.AsmDiff/README.md index 2dad02c4859..4b49d62a74d 100644 --- a/src/Microsoft.DotNet.AsmDiff/README.md +++ b/src/Microsoft.DotNet.AsmDiff/README.md @@ -21,6 +21,8 @@ AsmDiff is a command line tool which may be used to check the API changes betwee - `-dai|--DiffAssemblyInfo` - Enables diffing of the assembly level information like version, key, etc. - `-adm|--AlwaysDiffMembers` - By default if an entire class is added or removed we don't show the members, setting this option forces all the members to be shown instead. - `-hbm|--HighlightBaseMembers` - Highlight members that are interface implementations or overrides of a base member. +- `-hmo|--HighlightMemberOverrides` - Highlight members that are overrides of a base member. +- `-hii|--HighlightInterfaceImplementations` - Highlight members that are explicit interface implementations. - `-ft|--FlattenTypes` - Will flatten types so that all members available on the type show on the type not just the implemented ones. - `-gba|--GroupByAssembly` - Group the differences by assembly instead of flattening the namespaces. - `-eat|--ExcludeAddedTypes` - Do not show types that have been added to the new set of types. From 49ec843642460c57daee620b28386c29debec990 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Tue, 29 Mar 2022 12:55:42 -0700 Subject: [PATCH 2/8] Bug fix causing EII to unnecesarily show up as diffs when they shouldn't. --- .../Writers/CSharp/CSDeclarationWriter.Methods.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs index c378353f4a8..2e1adbfcba1 100644 --- a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs +++ b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs @@ -39,7 +39,7 @@ private void WriteMethodDefinition(IMethodDefinition method) { writeVisibility = false; } - + if (method.IsExplicitInterfaceMethod() || method.IsStaticConstructor) { writeVisibility = false; @@ -131,10 +131,13 @@ private void WriteMethodName(IMethodDefinition method) { IMethodImplementation methodImplementation = method.GetMethodImplementation(); object nullableAttributeArgument = methodImplementation.GetExplicitInterfaceMethodNullableAttributeArgument(_metadataReaderCache); - - WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument); - WriteSymbol("."); - WriteIdentifier(GetNormalizedMethodName(methodImplementation.ImplementedMethod.Name)); + if (nullableAttributeArgument is int iNullableAttributeArgument && iNullableAttributeArgument > 0) + { + WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument); + WriteSymbol("."); + WriteIdentifier(methodImplementation.ImplementedMethod.Name); + return; + } } else { From 6ecce1aee7c0824f3fe9fd91a02063b48dbec884 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Wed, 8 Jun 2022 11:12:56 -0700 Subject: [PATCH 3/8] Fix code preventing method names from showing up --- .../Writers/CSharp/CSDeclarationWriter.Methods.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs index 2e1adbfcba1..6ff6b47278a 100644 --- a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs +++ b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs @@ -131,13 +131,11 @@ private void WriteMethodName(IMethodDefinition method) { IMethodImplementation methodImplementation = method.GetMethodImplementation(); object nullableAttributeArgument = methodImplementation.GetExplicitInterfaceMethodNullableAttributeArgument(_metadataReaderCache); - if (nullableAttributeArgument is int iNullableAttributeArgument && iNullableAttributeArgument > 0) - { - WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument); - WriteSymbol("."); - WriteIdentifier(methodImplementation.ImplementedMethod.Name); - return; - } + + WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument); + WriteSymbol("."); + + WriteIdentifier(GetNormalizedMethodName(methodImplementation.ImplementedMethod.Name)); } else { From 774a6d8af50e395e23200c313d04eb3d702a8c72 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Wed, 8 Jun 2022 11:15:09 -0700 Subject: [PATCH 4/8] Spacing --- .../Writers/CSharp/CSDeclarationWriter.Methods.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs index 6ff6b47278a..39c0170385e 100644 --- a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs +++ b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Methods.cs @@ -134,7 +134,6 @@ private void WriteMethodName(IMethodDefinition method) WriteTypeName(methodImplementation.ImplementedMethod.ContainingType, noSpace: true, nullableAttributeArgument: nullableAttributeArgument); WriteSymbol("."); - WriteIdentifier(GetNormalizedMethodName(methodImplementation.ImplementedMethod.Name)); } else From e97331eff5339b7953531056cecdd1a1d47cd223 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Mon, 27 Jun 2022 13:26:33 -0700 Subject: [PATCH 5/8] Merge after rebase --- src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs index cb5a08c87fb..af390479e01 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs @@ -199,11 +199,11 @@ public override void Visit(MemberMapping member) { IDisposable style = null; - if (this.HighlightBaseMembers) + if (HighlightMemberOverrides || HighlightInterfaceImplementations) { - if (member.Representative.IsInterfaceImplementation()) + if (HighlightInterfaceImplementations && member.Representative.IsInterfaceImplementation()) style = _syntaxWriter.StartStyle(SyntaxStyle.InterfaceMember); - else if (member.Representative.IsOverride()) + else if (HighlightMemberOverrides && member.Representative.IsOverride()) style = _syntaxWriter.StartStyle(SyntaxStyle.InheritedMember); } From 82977320a674eabc39bb4064fa47a3aac16fb0fe Mon Sep 17 00:00:00 2001 From: carlossanlop <1175054+carlossanlop@users.noreply.github.com> Date: Thu, 7 Jul 2022 13:29:23 -0700 Subject: [PATCH 6/8] Make sure to also split the DiffCSharpWriter public property. Fix typo. --- src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs | 10 ++++++++++ .../DiffConfigurationOptions.cs | 2 +- src/Microsoft.DotNet.AsmDiff/DiffEngine.cs | 12 ++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs index af390479e01..b60b2c131a9 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs @@ -58,6 +58,16 @@ public DiffCSharpWriter(IStyleSyntaxWriter writer, MappingSettings settings) public bool IncludeMemberGroupHeadings { get; set; } + public bool HighlightBaseMembers + { + get => HighlightMemberOverrides && HighlightInterfaceImplementations; + set + { + HighlightMemberOverrides = true; + HighlightInterfaceImplementations = true; + } + } + public bool HighlightMemberOverrides { get; set; } public bool HighlightInterfaceImplementations { get; set; } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs b/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs index cf07c404545..2ceb51305be 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffConfigurationOptions.cs @@ -28,6 +28,6 @@ public enum DiffConfigurationOptions HightlightMemberOverrides = 0x40000, HighlightInterfaceImplementations = 0x80000, - HighlightBasesMembers = HightlightMemberOverrides | HighlightInterfaceImplementations, + HighlightBaseMembers = HightlightMemberOverrides | HighlightInterfaceImplementations, } } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs b/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs index b9c17e2fe7a..ac7ec88d4ae 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs @@ -60,8 +60,8 @@ private static ICciDifferenceWriter CreateExportWriter(DiffFormat format, TextWr return new DiffCSharpWriter(writer, mappingSettings, diffComments, includeAttributes) { IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), - HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), - HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers), + HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers), }; case DiffFormat.WordXml: case DiffFormat.Text: @@ -69,8 +69,8 @@ private static ICciDifferenceWriter CreateExportWriter(DiffFormat format, TextWr return new DiffCSharpWriter(writer, mappingSettings, diffComments, includeAttributes) { IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), - HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), - HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers), + HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers), }; default: throw new ArgumentOutOfRangeException("format"); @@ -166,8 +166,8 @@ private static void GetTokens(DiffConfiguration configuration, CancellationToken var writer = new ApiRecordingCSharpDiffWriter(diffRecorder, mappingSettings, includeAttributes) { IncludeAssemblyProperties = configuration.IsOptionSet(DiffConfigurationOptions.DiffAssemblyInfo), - HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), - HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBasesMembers), + HighlightMemberOverrides = configuration.IsOptionSet(DiffConfigurationOptions.HightlightMemberOverrides) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers), + HighlightInterfaceImplementations = configuration.IsOptionSet(DiffConfigurationOptions.HighlightInterfaceImplementations) || configuration.IsOptionSet(DiffConfigurationOptions.HighlightBaseMembers), }; WriteDiff(configuration, writer); From a71a5003e05004ca988ff4f3473938ab12b4443b Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Wed, 10 Aug 2022 10:59:06 -0700 Subject: [PATCH 7/8] Include attributes in final output files --- .../Extensions/CSharp/CSharpCciExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs b/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs index dd2d6f569b4..fda895d75e4 100644 --- a/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs +++ b/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs @@ -45,7 +45,7 @@ public static string GetCSharpDeclaration(this IDefinition definition, bool incl { using (var syntaxWriter = new TextSyntaxWriter(stringWriter)) { - var writer = new CSDeclarationWriter(syntaxWriter, new AttributesFilter(includeAttributes), false, true); + var writer = new CSDeclarationWriter(syntaxWriter, new AttributesFilter(true), false, true); var nsp = definition as INamespaceDefinition; var typeDefinition = definition as ITypeDefinition; From 05409e9c27e140a716dd45eaaa9bfa453bd6a47e Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Tue, 18 Oct 2022 14:16:33 -0700 Subject: [PATCH 8/8] Suppress unnecessary attributes. --- .../Comparers/AttributeComparer.cs | 4 +- .../Differs/Rules/TokenListDiffer.cs | 2 +- .../Extensions/CSharp/CSharpCciExtensions.cs | 4 +- .../Mappings/MappingSettings.cs | 10 ++-- .../Mappings/SimpleElementMapping.cs | 2 + .../Writers/CSharp/CSDeclarationHelper.cs | 9 ++-- .../CSharp/CSDeclarationWriter.Attributes.cs | 49 +++++++++---------- .../Writers/CSharp/CSDeclarationWriter.cs | 5 +- .../AttributesToExclude.txt | 20 ++++++++ .../DiffCSharpWriter.cs | 6 +-- .../DiffConfiguration.cs | 8 ++- .../DiffConfigurationExtensions.cs | 4 +- src/Microsoft.DotNet.AsmDiff/DiffDocument.cs | 4 +- src/Microsoft.DotNet.AsmDiff/DiffEngine.cs | 19 +++---- .../MarkdownDiffExporter.cs | 18 ++++--- .../Microsoft.DotNet.AsmDiff.csproj | 15 ++++-- src/Microsoft.DotNet.AsmDiff/Program.cs | 32 ++++++++++-- 17 files changed, 142 insertions(+), 69 deletions(-) create mode 100644 src/Microsoft.DotNet.AsmDiff/AttributesToExclude.txt diff --git a/src/Microsoft.Cci.Extensions/Comparers/AttributeComparer.cs b/src/Microsoft.Cci.Extensions/Comparers/AttributeComparer.cs index 21f60b14c89..f0d7a0e2a7e 100644 --- a/src/Microsoft.Cci.Extensions/Comparers/AttributeComparer.cs +++ b/src/Microsoft.Cci.Extensions/Comparers/AttributeComparer.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections; +using System.Collections.Generic; using Microsoft.Cci.Extensions; using Microsoft.Cci.Filters; using Microsoft.Cci.Writers.CSharp; @@ -19,7 +21,7 @@ public AttributeComparer() public AttributeComparer(ICciFilter filter, bool forCompilation) { - _helper = new CSDeclarationHelper(filter, forCompilation); + _helper = new CSDeclarationHelper(filter, new List(), forCompilation); } public override string GetKey(ICustomAttribute c) diff --git a/src/Microsoft.Cci.Extensions/Differs/Rules/TokenListDiffer.cs b/src/Microsoft.Cci.Extensions/Differs/Rules/TokenListDiffer.cs index a43744a0a33..8f740a2985d 100644 --- a/src/Microsoft.Cci.Extensions/Differs/Rules/TokenListDiffer.cs +++ b/src/Microsoft.Cci.Extensions/Differs/Rules/TokenListDiffer.cs @@ -57,7 +57,7 @@ private IEnumerable GetTokenList(IDefinition item) return DiffingService.GetTokenList(item); if (_declHelper == null) - _declHelper = new CSDeclarationHelper(new PublicOnlyCciFilter()); + _declHelper = new CSDeclarationHelper(new PublicOnlyCciFilter(), new List()); return _declHelper.GetTokenList(item); } diff --git a/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs b/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs index fda895d75e4..5423c8f4dc6 100644 --- a/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs +++ b/src/Microsoft.Cci.Extensions/Extensions/CSharp/CSharpCciExtensions.cs @@ -39,13 +39,13 @@ public static class CSharpCciExtensions (byte)'S', (byte)'e', (byte)'r', (byte)'v', (byte)'i', (byte)'c', (byte)'e', (byte)'s' }; - public static string GetCSharpDeclaration(this IDefinition definition, bool includeAttributes = false) + public static string GetCSharpDeclaration(this IDefinition definition, IEnumerable attributesToExclude) { using (var stringWriter = new StringWriter()) { using (var syntaxWriter = new TextSyntaxWriter(stringWriter)) { - var writer = new CSDeclarationWriter(syntaxWriter, new AttributesFilter(true), false, true); + var writer = new CSDeclarationWriter(syntaxWriter, new AttributesFilter(true), false, true, attributesToExclude); var nsp = definition as INamespaceDefinition; var typeDefinition = definition as ITypeDefinition; diff --git a/src/Microsoft.Cci.Extensions/Mappings/MappingSettings.cs b/src/Microsoft.Cci.Extensions/Mappings/MappingSettings.cs index a6f73281783..b2fb28b98d9 100644 --- a/src/Microsoft.Cci.Extensions/Mappings/MappingSettings.cs +++ b/src/Microsoft.Cci.Extensions/Mappings/MappingSettings.cs @@ -12,12 +12,14 @@ public class MappingSettings { public MappingSettings(bool excludeAttributes = true) { - this.ElementCount = 2; - this.Filter = new PublicOnlyCciFilter(excludeAttributes); - this.Comparers = CciComparers.Default; - this.DiffFactory = new ElementDifferenceFactory(); + ElementCount = 2; + Filter = new PublicOnlyCciFilter(excludeAttributes); + Comparers = CciComparers.Default; + DiffFactory = new ElementDifferenceFactory(); } + public IEnumerable AttributesToExclude { get; set; } + public ICciFilter Filter { get; set; } public IMappingDifferenceFilter DiffFilter { get; set; } diff --git a/src/Microsoft.Cci.Extensions/Mappings/SimpleElementMapping.cs b/src/Microsoft.Cci.Extensions/Mappings/SimpleElementMapping.cs index cfbdbedad90..cb45cbfa3fe 100644 --- a/src/Microsoft.Cci.Extensions/Mappings/SimpleElementMapping.cs +++ b/src/Microsoft.Cci.Extensions/Mappings/SimpleElementMapping.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections; +using System.Collections.Generic; using Microsoft.Cci.Differs; namespace Microsoft.Cci.Mappings diff --git a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationHelper.cs b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationHelper.cs index 48874785b1b..d44e03a7088 100644 --- a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationHelper.cs +++ b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationHelper.cs @@ -21,11 +21,14 @@ public class CSDeclarationHelper private TokenSyntaxWriter _tokenizer; private CSDeclarationWriter _tokenWriter; - public CSDeclarationHelper(ICciFilter filter, bool forCompilation = false, bool includePseudoCustomAttributes = false) + private readonly IEnumerable _attributesToExclude; + + public CSDeclarationHelper(ICciFilter filter, IEnumerable attributesToExclude, bool forCompilation = false, bool includePseudoCustomAttributes = false) { _filter = filter; _forCompilation = forCompilation; _includeFakeAttributes = includePseudoCustomAttributes; + _attributesToExclude = attributesToExclude; } public string GetString(IDefinition definition, int indentLevel = -1) @@ -92,7 +95,7 @@ private void EnsureStringWriter() StringWriter sw = new StringWriter(_string); TextSyntaxWriter tsw = new TextSyntaxWriter(sw); - _stringWriter = new CSDeclarationWriter(tsw, _filter, _forCompilation, _includeFakeAttributes); + _stringWriter = new CSDeclarationWriter(tsw, _filter, _forCompilation, _includeFakeAttributes, _attributesToExclude); } } @@ -101,7 +104,7 @@ private void EnsureTokenWriter() if (_tokenWriter == null) { _tokenizer = new TokenSyntaxWriter(); - _tokenWriter = new CSDeclarationWriter(_tokenizer, _filter, _forCompilation, _includeFakeAttributes); + _tokenWriter = new CSDeclarationWriter(_tokenizer, _filter, _forCompilation, _includeFakeAttributes, _attributesToExclude); } } } diff --git a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Attributes.cs b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Attributes.cs index c5a04ccb0ad..b38590f947b 100644 --- a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Attributes.cs +++ b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.Attributes.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; +using System.IO; using System.Linq; using System.Text; using Microsoft.Cci.Comparers; @@ -370,40 +372,33 @@ private static string EscapeChar(char c, bool inString) return c.ToString(); } - private static bool ExcludeSpecialAttribute(ICustomAttribute c) + private bool ExcludeSpecialAttribute(ICustomAttribute c) { string typeName = c.FullName(); - switch (typeName) + if (typeName == "System.ObsoleteAttribute") { - case "System.ParamArrayAttribute": return true; - case "System.Reflection.AssemblyDelaySignAttribute": return true; - case "System.Reflection.AssemblyKeyFileAttribute": return true; - case "System.Reflection.DefaultMemberAttribute": return true; - case "System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute": return true; - case "System.Runtime.CompilerServices.DynamicAttribute": return true; - case "System.Runtime.CompilerServices.ExtensionAttribute": return true; - case "System.Runtime.CompilerServices.FixedBufferAttribute": return true; - case "System.Runtime.CompilerServices.IsByRefLikeAttribute": return true; - case "System.Runtime.CompilerServices.IsReadOnlyAttribute": return true; - case "System.Runtime.CompilerServices.RequiredMemberAttribute": return true; - case "System.Runtime.CompilerServices.TupleElementNamesAttribute": return true; - case "System.ObsoleteAttribute": - { - var arg = c.Arguments.OfType().FirstOrDefault(); + var arg = c.Arguments.OfType().FirstOrDefault(); - if (arg?.Value is string) - { - string argValue = (string)arg.Value; - if (argValue is "Types with embedded references are not supported in this version of your compiler." - or "Constructors of types with required members are not supported in this version of your compiler.") - { - return true; - } - } - break; + if (arg?.Value is string) + { + string argValue = (string)arg.Value; + if (argValue is "Types with embedded references are not supported in this version of your compiler." + or "Constructors of types with required members are not supported in this version of your compiler.") + { + return true; } + } } + + foreach (string attributeToExclude in _attributesToExclude) + { + if (typeName.Equals(attributeToExclude)) + { + return true; + } + } + return false; } diff --git a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.cs b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.cs index e33b2094a27..1a04bfc56dd 100644 --- a/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.cs +++ b/src/Microsoft.Cci.Extensions/Writers/CSharp/CSDeclarationWriter.cs @@ -33,6 +33,8 @@ public partial class CSDeclarationWriter : ICciDeclarationWriter, IDisposable private bool _includeFakeAttributes; private bool _alwaysIncludeBase; + private readonly IEnumerable _attributesToExclude; + public CSDeclarationWriter(ISyntaxWriter writer) : this(writer, new PublicOnlyCciFilter()) { @@ -56,10 +58,11 @@ public CSDeclarationWriter(ISyntaxWriter writer, ICciFilter filter, bool forComp _metadataReaderCache = new SRMetadataPEReaderCache(); } - public CSDeclarationWriter(ISyntaxWriter writer, ICciFilter filter, bool forCompilation, bool includePseudoCustomAttributes = false) + public CSDeclarationWriter(ISyntaxWriter writer, ICciFilter filter, bool forCompilation, bool includePseudoCustomAttributes, IEnumerable attributesToExclude) : this(writer, filter, forCompilation) { _includeFakeAttributes = includePseudoCustomAttributes; + _attributesToExclude = attributesToExclude; } public bool ForCompilation diff --git a/src/Microsoft.DotNet.AsmDiff/AttributesToExclude.txt b/src/Microsoft.DotNet.AsmDiff/AttributesToExclude.txt new file mode 100644 index 00000000000..0c34a8b0a0d --- /dev/null +++ b/src/Microsoft.DotNet.AsmDiff/AttributesToExclude.txt @@ -0,0 +1,20 @@ +Microsoft.AspNetCore.DataProtection.ApplyPolicyAttribute +System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute +System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute +System.ParamArrayAttribute +System.Reflection.AssemblyDelaySignAttribute +System.Reflection.AssemblyKeyFileAttribute +System.Reflection.DefaultMemberAttribute +System.Runtime.CompilerServices.AsyncStateMachineAttribute +System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute +System.Runtime.CompilerServices.CompilerGeneratedAttribute +System.Runtime.CompilerServices.DynamicAttribute +System.Runtime.CompilerServices.ExtensionAttribute +System.Runtime.CompilerServices.FixedBufferAttribute +System.Runtime.CompilerServices.IsByRefLikeAttribute +System.Runtime.CompilerServices.IsReadOnlyAttribute +System.Runtime.CompilerServices.NullableAttribute +System.Runtime.CompilerServices.NullableContextAttribute +System.Runtime.CompilerServices.RequiredMemberAttribute +System.Runtime.CompilerServices.TupleElementNamesAttribute +System.Runtime.InteropServices.StructLayoutAttribute diff --git a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs index b60b2c131a9..0da888d1de2 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffCSharpWriter.cs @@ -32,7 +32,7 @@ public class DiffCSharpWriter : MappingsTypeMemberTraverser, IDiffingService, IC private readonly IEnumerable _diffComments; public DiffCSharpWriter(IStyleSyntaxWriter writer, MappingSettings settings, IEnumerable diffComments) - : this(writer, settings, diffComments, includePseudoCustomAttributes:false) + : this(writer, settings, diffComments, includePseudoCustomAttributes: false) { } @@ -41,11 +41,11 @@ public DiffCSharpWriter(IStyleSyntaxWriter writer, MappingSettings settings, IEn { _syntaxWriter = writer; _settings = InitializeSettings(settings); - _formatter = new CSDeclarationWriter(_syntaxWriter, _settings.Filter, forCompilation: false, includePseudoCustomAttributes: includePseudoCustomAttributes) + _formatter = new CSDeclarationWriter(_syntaxWriter, _settings.Filter, forCompilation: false, includePseudoCustomAttributes: includePseudoCustomAttributes, _settings.AttributesToExclude) { LangVersion = CSDeclarationWriter.LangVersionPreview }; - _declHelper = new CSDeclarationHelper(_settings.Filter, forCompilation: false, includePseudoCustomAttributes: includePseudoCustomAttributes); + _declHelper = new CSDeclarationHelper(_settings.Filter, _settings.AttributesToExclude, forCompilation: false, includePseudoCustomAttributes: includePseudoCustomAttributes); _diffComments = diffComments ?? Enumerable.Empty(); } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs b/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs index 808aaef5ec3..7a1710c0f5d 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffConfiguration.cs @@ -1,6 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections; +using System.Collections.Generic; + namespace Microsoft.DotNet.AsmDiff { public sealed class DiffConfiguration @@ -19,11 +22,12 @@ public DiffConfiguration() DiffConfigurationOptions.HighlightInterfaceImplementations; } - public DiffConfiguration(AssemblySet left, AssemblySet right, DiffConfigurationOptions options) + public DiffConfiguration(AssemblySet left, AssemblySet right, DiffConfigurationOptions options, IEnumerable attributesToExclude) { Left = left; Right = right; Options = options; + AttributesToExclude = attributesToExclude; } public AssemblySet Left { get; private set; } @@ -44,5 +48,7 @@ public bool IsDiff } public DiffConfigurationOptions Options { get; private set; } + + public IEnumerable AttributesToExclude { get; private set; } } } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffConfigurationExtensions.cs b/src/Microsoft.DotNet.AsmDiff/DiffConfigurationExtensions.cs index dc5fe37a490..546b385a644 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffConfigurationExtensions.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffConfigurationExtensions.cs @@ -15,7 +15,7 @@ public static DiffConfiguration UpdateOptions(this DiffConfiguration configurati { var left = configuration.Left; var right = configuration.Right; - return new DiffConfiguration(left, right, options); + return new DiffConfiguration(left, right, options, configuration.AttributesToExclude); } public static bool IsOptionSet(this DiffConfiguration configuration, DiffConfigurationOptions option) @@ -147,7 +147,7 @@ private static DiffConfiguration UpdateAssemblies(this DiffConfiguration configu var newLeft = isLeft ? assemblySet : configuration.Left; var newRight = isRight ? assemblySet : configuration.Right; - return new DiffConfiguration(newLeft, newRight, configuration.Options); + return new DiffConfiguration(newLeft, newRight, configuration.Options, configuration.AttributesToExclude); } } } diff --git a/src/Microsoft.DotNet.AsmDiff/DiffDocument.cs b/src/Microsoft.DotNet.AsmDiff/DiffDocument.cs index 3f17203cc84..b23c7a8fb57 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffDocument.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffDocument.cs @@ -13,13 +13,15 @@ public sealed class DiffDocument public AssemblySet Right { get; private set; } public ReadOnlyCollection Lines { get; private set; } public ReadOnlyCollection ApiDefinitions { get; private set; } + public IEnumerable AttributesToExclude { get; private set; } - public DiffDocument(AssemblySet left, AssemblySet right, IEnumerable lines, IEnumerable apiDefinitions) + public DiffDocument(AssemblySet left, AssemblySet right, IEnumerable lines, IEnumerable apiDefinitions, IEnumerable attributesToExclude) { Left = left; Right = right; Lines = new ReadOnlyCollection(lines.ToArray()); ApiDefinitions = new ReadOnlyCollection(apiDefinitions.ToArray()); + AttributesToExclude = attributesToExclude; } public bool IsDiff diff --git a/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs b/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs index ac7ec88d4ae..1714de4232c 100644 --- a/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs +++ b/src/Microsoft.DotNet.AsmDiff/DiffEngine.cs @@ -115,14 +115,15 @@ public static MappingSettings GetMappingSettings(DiffConfiguration configuration : new CommonTypesMappingDifferenceFilter(mappingDifferenceFilter, includeAddedTypes, includeRemovedTypes); return new MappingSettings - { - Filter = cciFilter, - DiffFilter = actualFilter, - IncludeForwardedTypes = true, - GroupByAssembly = configuration.IsOptionSet(DiffConfigurationOptions.GroupByAssembly), - FlattenTypeMembers = configuration.IsOptionSet(DiffConfigurationOptions.FlattenTypes), - AlwaysDiffMembers = configuration.IsOptionSet(DiffConfigurationOptions.AlwaysDiffMembers) - }; + { + AttributesToExclude = configuration.AttributesToExclude, + Filter = cciFilter, + DiffFilter = actualFilter, + IncludeForwardedTypes = true, + GroupByAssembly = configuration.IsOptionSet(DiffConfigurationOptions.GroupByAssembly), + FlattenTypeMembers = configuration.IsOptionSet(DiffConfigurationOptions.FlattenTypes), + AlwaysDiffMembers = configuration.IsOptionSet(DiffConfigurationOptions.AlwaysDiffMembers) + }; } private static ICciFilter GetFilter(DiffConfiguration configuration) @@ -150,7 +151,7 @@ public static DiffDocument BuildDiffDocument(DiffConfiguration configuration, Ca IEnumerable lines = GetLines(tokens, cancellationToken); AssemblySet left = configuration.Left; AssemblySet right = configuration.Right; - return new DiffDocument(left, right, lines, apiDefinitions); + return new DiffDocument(left, right, lines, apiDefinitions, configuration.AttributesToExclude); } catch (OperationCanceledException) { diff --git a/src/Microsoft.DotNet.AsmDiff/MarkdownDiffExporter.cs b/src/Microsoft.DotNet.AsmDiff/MarkdownDiffExporter.cs index 22894fcc2f7..2b4f148c881 100644 --- a/src/Microsoft.DotNet.AsmDiff/MarkdownDiffExporter.cs +++ b/src/Microsoft.DotNet.AsmDiff/MarkdownDiffExporter.cs @@ -17,13 +17,15 @@ public sealed class MarkdownDiffExporter private readonly string _path; private readonly bool _includeTableOfContents; private readonly bool _createFilePerNamespace; + private readonly IEnumerable _attributesToExclude; - public MarkdownDiffExporter(DiffDocument diffDocument, string path, bool includeTableOfContents, bool createFilePerNamespace) + public MarkdownDiffExporter(DiffDocument diffDocument, string path, bool includeTableOfContents, bool createFilePerNamespace, IEnumerable attributesToExclude) { _diffDocument = diffDocument; _path = path; _includeTableOfContents = includeTableOfContents; _createFilePerNamespace = createFilePerNamespace; + _attributesToExclude = attributesToExclude; } public void Export() @@ -111,14 +113,14 @@ private void WriteDiffForNamespace(StreamWriter writer, DiffApiDefinition topLev writer.WriteLine(); } - private static void WriteDiff(StreamWriter writer, DiffApiDefinition topLevelApi) + private void WriteDiff(StreamWriter writer, DiffApiDefinition topLevelApi) { writer.WriteLine("``` diff"); WriteDiff(writer, topLevelApi, 0); writer.WriteLine("```"); } - private static void WriteDiff(StreamWriter writer, DiffApiDefinition api, int level) + private void WriteDiff(StreamWriter writer, DiffApiDefinition api, int level) { bool hasChildren = api.Children.Any(); @@ -131,8 +133,8 @@ private static void WriteDiff(StreamWriter writer, DiffApiDefinition api, int le // Let's see whether the syntax actually changed. For some cases the syntax might not // diff, for example, when attribute declarations have changed. - string left = api.Left.GetCSharpDeclaration(); - string right = api.Right.GetCSharpDeclaration(); + string left = api.Left.GetCSharpDeclaration(_attributesToExclude); + string right = api.Right.GetCSharpDeclaration(_attributesToExclude); if (string.Equals(left, right, StringComparison.OrdinalIgnoreCase)) diff = DifferenceType.Unchanged; @@ -174,7 +176,7 @@ private static void WriteDiff(StreamWriter writer, DiffApiDefinition api, int le } } - private static void WriteDiff(TextWriter writer, string marker, string indent, string suffix, IDefinition api) + private void WriteDiff(TextWriter writer, string marker, string indent, string suffix, IDefinition api) { IEnumerable lines = GetCSharpDecalarationLines(api); bool isFirst = true; @@ -194,9 +196,9 @@ private static void WriteDiff(TextWriter writer, string marker, string indent, s writer.WriteLine(suffix); } - private static IEnumerable GetCSharpDecalarationLines(IDefinition api) + private IEnumerable GetCSharpDecalarationLines(IDefinition api) { - string text = api.GetCSharpDeclaration(); + string text = api.GetCSharpDeclaration(_attributesToExclude); using (var reader = new StringReader(text)) { string line; diff --git a/src/Microsoft.DotNet.AsmDiff/Microsoft.DotNet.AsmDiff.csproj b/src/Microsoft.DotNet.AsmDiff/Microsoft.DotNet.AsmDiff.csproj index d25f8f66da1..38df18810c1 100644 --- a/src/Microsoft.DotNet.AsmDiff/Microsoft.DotNet.AsmDiff.csproj +++ b/src/Microsoft.DotNet.AsmDiff/Microsoft.DotNet.AsmDiff.csproj @@ -1,5 +1,5 @@  - + $(NetCurrent) @@ -11,7 +11,7 @@ Open true - + @@ -23,7 +23,7 @@ - + @@ -35,4 +35,13 @@ + + + + + + + PreserveNewest + + diff --git a/src/Microsoft.DotNet.AsmDiff/Program.cs b/src/Microsoft.DotNet.AsmDiff/Program.cs index 2155613de1a..67b4155e3ed 100644 --- a/src/Microsoft.DotNet.AsmDiff/Program.cs +++ b/src/Microsoft.DotNet.AsmDiff/Program.cs @@ -1,11 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using McMaster.Extensions.CommandLineUtils; using System; +using System.Collections.Generic; using System.IO; using System.Text; using System.Threading; +using McMaster.Extensions.CommandLineUtils; namespace Microsoft.DotNet.AsmDiff { @@ -76,6 +77,11 @@ public class Program [Option("-l|--Language", "Provide a languagetag for localized content. If this parameter is not provided the environments default language will be used. Currently language specific content is only available in Markdown Writer.", CommandOptionType.SingleValue)] public string Language { get; set; } + [Option("-aef|--AttributesToExcludeFile", "Indicates the location of the text file containing the list of the attributes to ignore. The default file is 'AttributesToExclude', which is included next to this tool's binaries.", CommandOptionType.SingleValue)] + public string AttributesToExcludeFilePath { get; set; } + + public readonly List AttributesToExclude = new List(); + public void OnExecute() { if (string.IsNullOrEmpty(NewSet)) @@ -99,18 +105,38 @@ public void OnExecute() Thread.CurrentThread.CurrentUICulture = cultureInfo; } + if (string.IsNullOrEmpty(AttributesToExcludeFilePath)) + { + AttributesToExcludeFilePath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), "AttributesToExclude.txt"); + } + + if (!File.Exists(AttributesToExcludeFilePath)) + { + throw new FileNotFoundException($"Excluded attributes file path not found: {AttributesToExcludeFilePath}"); + } + + List attributesToExclude = new(); + using (StreamReader reader = File.OpenText(AttributesToExcludeFilePath)) + { + string line; + while ((line = reader.ReadLine()) != null) + { + attributesToExclude.Add(line); + } + } + DiffConfigurationOptions options = GetDiffOptions(); DiffFormat diffFormat = GetDiffFormat(); AssemblySet oldAssemblies = AssemblySet.FromPaths(OldSetName, OldSet); AssemblySet newAssemblies = AssemblySet.FromPaths(NewSetName, NewSet); - DiffConfiguration diffConfiguration = new DiffConfiguration(oldAssemblies, newAssemblies, options); + DiffConfiguration diffConfiguration = new DiffConfiguration(oldAssemblies, newAssemblies, options, attributesToExclude); if (diffFormat == DiffFormat.Md) { DiffDocument diffDocument = DiffEngine.BuildDiffDocument(diffConfiguration); - var markdownDiffExporter = new MarkdownDiffExporter(diffDocument, OutFile, IncludeTableOfContents, CreateFilePerNamespace); + var markdownDiffExporter = new MarkdownDiffExporter(diffDocument, OutFile, IncludeTableOfContents, CreateFilePerNamespace, attributesToExclude); markdownDiffExporter.Export(); } else