Unexplained Duplicates in Method Signatures Query

I'm using the exhibited code to extract all method signatures from a .cs file that in this use case contains 2 declarations of the same class, but in different namespaces like this, in one file:
namespace CrossCut.Cache.Api.Services
{
public partial class CacheServices
}
namespace CrossCut.Cache.Api.Services.V4
{
public class CacheServices
}
...
When I use this code to extract all the method signatures contain in both namespaces:
namespace CrossCut.Cache.Api.Services
{
public partial class CacheServices
}
namespace CrossCut.Cache.Api.Services.V4
{
public class CacheServices
}
...
When I use this code to extract all the method signatures contain in both namespaces:
cs public static void Execute(string filePath, bool sort) { var methods = new List<MethodInfoProvider>(); if (!FilePathValidator.ValidateClassFilePath(filePath)) { Console.WriteLine($"Invalid class file path: {filePath}"); return; } var reader = new SourceFileReader(); var classes = reader.ReadClasses(filePath); foreach (var cls in classes) { methods.AddRange(cls.Methods); var sigs = methods.Select(m => m.Signature); if (sort) { sigs = sigs.OrderBy(s => s); } foreach (var sig in sigs) { Console.WriteLine($"V3,'{filePath}','{cls.NamespaceName}','{cls.ClassName}','{sig}'"); } } }
I get duplicate signature strings in the output, while there are no such duplicates in the actual code:
I get duplicate signature strings in the output, while there are no such duplicates in the actual code:
sh "CacheServices.V4.cs","Cache.Api.Services.V4","CacheServices","pbrsc(svch cch, IdValidationResponse responseCache, LogHelper logHelper)" "CacheServices.V4.cs","Cache.Api.Services.V4","CacheServices","pbrsc(svch cch, IdValidationResponse responseCache, LogHelper logHelper)" "CacheServices.V4.cs","Cache.Api.Services.V4","CacheServices","pbrsc(svch cch, Lineage.LineageSearchResponse responseCache, LogHelper logHelper)" "CacheServices.V4.cs","Cache.Api.Services.V4","CacheServices","pbrsc(svch cch, Lineage.LineageSearchResponse responseCache, LogHelper logHelper)" ``` I can't figure why there are duplicates in the console outout, but not in the file. There couldn't be in the file, or it would not compile.
2 Replies
canton7
canton77d ago
What is SourceFileReader? It seems the problem lies somewhere in that, but I've no idea what it is or where it comes from
VoidPointer
VoidPointerOP6d ago
Thanks for looking at it at least. The problem was I was calling methods.AddRange(cls.Methods) for each class, or something like that - my commits were quite badly thought out the time and I can't find the error, and with two classes with the same method in one file I was getting the duplicates.

Did you find this page helpful?