Ignore code attributes in C#
I am comparing generated web service proxy C# code across server versions. I'd like to be able to disable code attributes compare. Example;
File A
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceCatalogBinding", Namespace="http://www.esri.com/schemas/ArcGIS/9.3")]
File B
[System.Web.Services.WebServiceBindingAttribute(Name="ServiceCatalogBinding", Namespace="http://www.esri.com/schemas/ArcGIS/10.1")]
I don't want to see this as being different.
I don't want to have to manually search and replace in many files.
I just want to turn that off.
Granted structurally it makes a difference.
But I'd like to be able to ignore that easily.
Alain
-
Teknologist commented
This could be expanded to accommodate ignoring other types of code blocks such as the namespace, using, regions etc.
I have a use case where I need to compare projects that are very similar as they are based on the same code, however we change the Namespace for the project, because of this almost every file shows as different even if there are only a few small changes.
The different Namespaces are to accommodate different customers or projects where I can't just reuse the existing namespace. -
Alain d'Espaignet commented
I don't know what it is that you use under the hood to to structure compare but I can tell it is wrong!
Here I found this program that uses Rosyln to do code syntax tree compare...
https://github.com/AlexGhiondea/CodeDiff
I modified it file TextCodeDiff.cs line 111 to skip the string literal tokensforeach (var added in _codeDiff.GetModified())
{
// Ignore string literal differences as in attributes
// https://github.com/AlexGhiondea/CodeDiff
if (!added.Before.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.StringLiteralToken) &&
!added.After.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.StringLiteralToken))
{
ColorSection(rtbAfter, added.After.Span.Start, added.After.Span.Length, Color.LightGreen);
ColorSection(rtbBefore, added.Before.Span.Start, added.Before.Span.Length, Color.LightSalmon);
}
}
This yields the right result.
Your product is wrong string literal differences do not constitute code structure differences.
Sorry I can't attach a picture here to show you.