Skip to content

Separate GetResourceString method with defaultString value. #51073

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

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
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
16 changes: 9 additions & 7 deletions src/libraries/Common/src/System/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ private static bool UsingResourceKeys() =>
false;
#endif

internal static string GetResourceString(string resourceKey, string? defaultString = null)
internal static string GetResourceString(string resourceKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a difference from its .vb counterpart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter? The only place where it's used is in archived Microsoft.VisualBasic.Core library

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that it matters, but I wanted to call it out.
cc: @tarekgh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place where it's used is in archived Microsoft.VisualBasic.Core library

that is right. if this change is not affecting Microsoft.VisualBasic.Core, it should be ok. But should we just keep C# and VB match for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not touch Microsoft.VisualBasic.Core code and I don't think the consistency matters here.

{
if (UsingResourceKeys())
{
return defaultString ?? resourceKey;
return resourceKey;
}

string? resourceString = null;
Expand All @@ -42,14 +42,16 @@ internal static string GetResourceString(string resourceKey, string? defaultStri
}
catch (MissingManifestResourceException) { }

if (defaultString != null && resourceKey.Equals(resourceString))
{
return defaultString;
}

return resourceString!; // only null if missing resources
}

internal static string GetResourceString(string resourceKey, string defaultString)
{
string resourceString = GetResourceString(resourceKey);

return resourceKey == resourceString || resourceString == null ? defaultString : resourceString;
}

internal static string Format(string resourceFormat, object? p1)
{
if (UsingResourceKeys())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override bool Equals(object? obj) =>
/// <summary>
/// Looks up the localized name of a given category.
/// </summary>
protected virtual string? GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value, null);
protected virtual string? GetLocalizedString(string value) => SR.GetResourceString("PropertyCategory" + value);

public override bool IsDefaultAttribute() => Category == Default.Category;
}
Expand Down
6 changes: 0 additions & 6 deletions src/libraries/System.Private.CoreLib/src/System/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ internal static partial class SR
private static int _infinitelyRecursingCount;
private static bool _resourceManagerInited;

// Needed for debugger integration
internal static string GetResourceString(string resourceKey)
{
return GetResourceString(resourceKey, null);
}

private static string InternalGetResourceString(string key)
{
if (key.Length == 0)
Expand Down