Skip to content

Commit

Permalink
Initial multi-framework experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDesmond-ca committed Apr 14, 2024
1 parent aa0a09b commit e5888b5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/LibYear.Core/FileTypes/XmlProjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ public abstract class XmlProjectFile : IProjectFile
private readonly string[] _packageAttributeNames;
private readonly string _versionAttributeName;

class PackageComparer : EqualityComparer<XElement>
{
public override bool Equals(XElement? x1, XElement? x2)
{
if (x1 == null && x2 == null)
return true;
else if (x1 == null || x2 == null)
return false;

return (x1.Attribute("Include")?.Value == x2.Attribute("Include")?.Value);
}

public override int GetHashCode(XElement x)
{
return x.Attribute("Include").Value.GetHashCode();

Check warning on line 29 in src/LibYear.Core/FileTypes/XmlProjectFile.cs

View workflow job for this annotation

GitHub Actions / Build

Dereference of a possibly null reference.

Check warning on line 29 in src/LibYear.Core/FileTypes/XmlProjectFile.cs

View workflow job for this annotation

GitHub Actions / Build

Dereference of a possibly null reference.

Check warning on line 29 in src/LibYear.Core/FileTypes/XmlProjectFile.cs

View workflow job for this annotation

GitHub Actions / Code-Quality

Dereference of a possibly null reference.

Check warning on line 29 in src/LibYear.Core/FileTypes/XmlProjectFile.cs

View workflow job for this annotation

GitHub Actions / Code-Quality

Dereference of a possibly null reference.
}
}

protected XmlProjectFile(string filename, string contents, string elementName, string[] packageAttributeNames, string versionAttributeName)
{
FileName = filename;
Expand All @@ -21,7 +39,8 @@ protected XmlProjectFile(string filename, string contents, string elementName, s
_versionAttributeName = versionAttributeName;

_xmlContents = XDocument.Parse(contents);
Packages = _xmlContents.Descendants(elementName)
PackageComparer comparer = new PackageComparer();
Packages = _xmlContents.Descendants(elementName).Distinct(comparer)
.ToDictionary(
d => packageAttributeNames.Select(p => d.Attribute(p)?.Value ?? d.Element(p)?.Value).FirstOrDefault(v => v != null)!,
d => ParseCurrentVersion(d, versionAttributeName)
Expand Down

0 comments on commit e5888b5

Please sign in to comment.