Skip to content

Commit

Permalink
First part of removing ToLowerInvariant in projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Apr 5, 2024
1 parent c8448af commit 1e3d91a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
41 changes: 19 additions & 22 deletions FRBDK/Glue/Glue/VSHelpers/Projects/VisualStudioProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class VisualStudioProject : ProjectBase
#region Properties

protected Dictionary<string, ProjectItem> mBuildItemDictionaries =
new Dictionary<string, ProjectItem>();
new Dictionary<string, ProjectItem>(StringComparer.OrdinalIgnoreCase);

public IEnumerable<ProjectItem> EvaluatedItems
{
Expand Down Expand Up @@ -289,7 +289,7 @@ public ProjectItem AddContentBuildItem(string absoluteFile, SyncedProjectRelativ
{
// The items in the dictionary must be to-lower on some
// platforms, and ProcessPath takes care of this.
mBuildItemDictionaries.Add(itemInclude.ToLowerInvariant(), buildItem);
mBuildItemDictionaries.Add(itemInclude, buildItem);
}
catch
{
Expand Down Expand Up @@ -586,7 +586,7 @@ public override void Load(string fileName)
{
ProjectItem buildItem = mProject.AllEvaluatedItems.ElementAt(i);

string includeToLower = buildItem.EvaluatedInclude.ToLowerInvariant();
string evaluatedInclude = buildItem.EvaluatedInclude;

if (buildItem.IsImported)
{
Expand All @@ -598,10 +598,10 @@ public override void Load(string fileName)
// sure why, but if we check for the isIncluded flag it seems to fix it, and isIncluded doesn't seem to be true
// on things added by Glue - and that's ultimately what we want to check duplicates on.
}
else if (mBuildItemDictionaries.ContainsKey(includeToLower))
else if (mBuildItemDictionaries.ContainsKey(evaluatedInclude))
{
// do the two have the same
var areSameItemType = buildItem.ItemType == mBuildItemDictionaries[includeToLower].ItemType;
var areSameItemType = buildItem.ItemType == mBuildItemDictionaries[evaluatedInclude].ItemType;

if(areSameItemType)
{
Expand All @@ -614,7 +614,7 @@ public override void Load(string fileName)
else
{
mBuildItemDictionaries.Add(
buildItem.UnevaluatedInclude.ToLowerInvariant(),
buildItem.UnevaluatedInclude,
buildItem);
}
}
Expand Down Expand Up @@ -725,7 +725,7 @@ public ProjectItem GetItem(string itemName, bool standardizeItemName)
}
else
{
itemName = itemName.Replace("/", "\\").ToLowerInvariant();
itemName = itemName.Replace("/", "\\");
}
if (!mBuildItemDictionaries.ContainsKey(itemName))
{
Expand Down Expand Up @@ -977,13 +977,13 @@ protected ProjectItem AddCodeBuildItem(string fileName, bool isSyncedProject, st
fileName = FileManager.MakeRelative(fileName, this.Directory);
}

string fileNameToLower = fileName.Replace('/', '\\').ToLowerInvariant();
string fleNameFixedSlashes = fileName.Replace('/', '\\');



if (mBuildItemDictionaries.ContainsKey(fileNameToLower))
if (mBuildItemDictionaries.ContainsKey(fleNameFixedSlashes))
{
return mBuildItemDictionaries[fileNameToLower];
return mBuildItemDictionaries[fleNameFixedSlashes];
}


Expand All @@ -1010,7 +1010,7 @@ protected ProjectItem AddCodeBuildItem(string fileName, bool isSyncedProject, st
}


mBuildItemDictionaries.Add(fileNameToLower, item);
mBuildItemDictionaries.Add(fleNameFixedSlashes, item);

return item;
}
Expand All @@ -1030,9 +1030,7 @@ public string GetNugetPackageVersion(string packageName)

public bool HasPackage(string packageName, out string existingVersionNumber)
{
var packageNameToLower = packageName.ToLowerInvariant();

if (mBuildItemDictionaries.TryGetValue(packageNameToLower, out var buildItem))
if (mBuildItemDictionaries.TryGetValue(packageName, out var buildItem))
{
if (buildItem.ItemType == "PackageReference" && buildItem.HasMetadata("Version"))
{
Expand Down Expand Up @@ -1087,14 +1085,14 @@ public void AddNugetPackage(string packageName, string versionNumber)
{
ProjectItem projectItem = this.Project.AddItem("PackageReference", packageName).First();
projectItem.SetMetadataValue("Version", versionNumber);
mBuildItemDictionaries.Add(packageName.ToLowerInvariant(), projectItem);
mBuildItemDictionaries.Add(packageName, projectItem);
Project.ReevaluateIfNecessary();
}
}

public bool RemoveItem(ProjectItem buildItem)
{
string itemName = buildItem.EvaluatedInclude.Replace("/", "\\").ToLowerInvariant();
string itemName = buildItem.EvaluatedInclude.Replace("/", "\\");

return RemoveItem(itemName);
}
Expand All @@ -1119,7 +1117,7 @@ public override bool RemoveItem(string itemName)

ProjectItem itemToRemove = null;

itemName = itemName.Replace("/", "\\").ToLowerInvariant();
itemName = itemName.Replace("/", "\\");
bool removed = false;
if (mBuildItemDictionaries.TryGetValue(itemName, out var buildItem))
{
Expand All @@ -1133,11 +1131,11 @@ public override bool RemoveItem(string itemName)

public void RenameInDictionary(string oldName, string newName, ProjectItem item)
{
mBuildItemDictionaries.Remove(oldName.Replace("/", "\\").ToLowerInvariant());
mBuildItemDictionaries.Remove(oldName.Replace("/", "\\"));

if (!mBuildItemDictionaries.ContainsKey(newName.Replace("/", "\\").ToLowerInvariant()))
if (!mBuildItemDictionaries.ContainsKey(newName.Replace("/", "\\")))
{
mBuildItemDictionaries.Add(newName.Replace("/", "\\").ToLowerInvariant(), item);
mBuildItemDictionaries.Add(newName.Replace("/", "\\"), item);
}
}

Expand All @@ -1161,8 +1159,7 @@ private void FindRootNamespace()

private ProjectItem GetNugetPackageReference(string packageName)
{
var packageNameToLower = packageName.ToLowerInvariant();
if (!mBuildItemDictionaries.TryGetValue(packageNameToLower, out var item))
if (!mBuildItemDictionaries.TryGetValue(packageName, out var item))
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion FRBDK/Glue/GlueCommon/VSHelper/Projects/ProjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public string GetAbsoluteContentFolder()

public string StandardizeItemName(string itemName)
{
itemName = itemName.ToLowerInvariant().Replace("/", "\\");
itemName = itemName.Replace("/", "\\");

if (!FileManager.IsRelative(itemName))
{
Expand Down

0 comments on commit 1e3d91a

Please sign in to comment.