Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StronglyTypedResourceBuilder to replace Hashtable with Dictionary #8677

Merged
merged 4 commits into from
Feb 23, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static CodeCompileUnit InternalCreate(

// Verify the resource names are valid property names, and they don't conflict. This includes checking for
// language-specific keywords, translating spaces to underscores, etc.
var cleanedResourceList = VerifyResourceNames(resourceList, codeProvider, errors, out Hashtable reverseFixupTable);
var cleanedResourceList = VerifyResourceNames(resourceList, codeProvider, errors, out Dictionary<string, string> reverseFixupTable);

// Verify the class name is legal.
string className = baseName;
Expand Down Expand Up @@ -418,7 +418,8 @@ private static CodeCompileUnit InternalCreate(
foreach ((string propertyName, ResourceData resource) in cleanedResourceList)
{
// The resourceName will be the original value, before fixups, if any.
string resourceName = (string)reverseFixupTable[propertyName] ?? propertyName;
reverseFixupTable.TryGetValue(propertyName, out string resourceName);
resourceName ??= propertyName;
if (!DefineResourceFetchingProperty(
propertyName,
resourceName,
Expand Down Expand Up @@ -861,9 +862,9 @@ private static SortedList<string, ResourceData> VerifyResourceNames(
Dictionary<string, ResourceData> resourceList,
CodeDomProvider codeProvider,
List<string> errors,
out Hashtable reverseFixupTable)
out Dictionary<string, string> reverseFixupTable)
{
reverseFixupTable = new Hashtable(0, StringComparer.InvariantCultureIgnoreCase);
reverseFixupTable = new(0, StringComparer.InvariantCultureIgnoreCase);
SortedList<string, ResourceData> cleanedResourceList = new(resourceList.Count, StringComparer.InvariantCultureIgnoreCase);

foreach (KeyValuePair<string, ResourceData> entry in resourceList)
Expand Down Expand Up @@ -898,8 +899,7 @@ private static SortedList<string, ResourceData> VerifyResourceNames(
}

// Now see if we've already mapped another key to the same name.
string oldDuplicateKey = (string)reverseFixupTable[newKey];
if (oldDuplicateKey is not null)
if (reverseFixupTable.TryGetValue(newKey, out string oldDuplicateKey) && oldDuplicateKey is not null)
{
// We can't handle this key nor the previous one. Remove the old one.
if (!errors.Contains(oldDuplicateKey))
Expand Down Expand Up @@ -929,8 +929,7 @@ private static SortedList<string, ResourceData> VerifyResourceNames(
{
// There was a case-insensitive conflict between two keys. Or possibly one key was fixed up in a
// way that conflicts with another key (ie, "A B" and "A_B").
string fixedUp = (string)reverseFixupTable[key];
if (fixedUp is not null)
if (reverseFixupTable.TryGetValue(key, out string fixedUp) && fixedUp is not null)
{
if (!errors.Contains(fixedUp))
{
Expand Down