Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/ReferenceCop/Providers/ProjectTagProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ReferenceCop
{
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
Expand All @@ -12,20 +13,25 @@ public class ProjectTagProvider : IProjectTagProvider
internal const string ProjectTagNode = "ProjectTag";
internal const string UnknownProjectTag = "Unknown";

private readonly ConcurrentDictionary<string, string> cache = new ConcurrentDictionary<string, string>();

public string GetProjectTag(string projectFilePath)
{
if (!File.Exists(projectFilePath))
return this.cache.GetOrAdd(projectFilePath, path =>
{
return UnknownProjectTag;
}
if (!File.Exists(path))
{
return UnknownProjectTag;
}

var projectFile = XDocument.Load(projectFilePath);
var projectTag = projectFile
.Descendants(PropertyGroupNode)
.Elements(ProjectTagNode)
.FirstOrDefault()?.Value;
var projectFile = XDocument.Load(path);
var projectTag = projectFile
.Descendants(PropertyGroupNode)
.Elements(ProjectTagNode)
.FirstOrDefault()?.Value;

return projectTag ?? UnknownProjectTag;
return projectTag ?? UnknownProjectTag;
});
}
}
}
Loading