-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Prefer use of interpolated strings in PresentationUI and ReachFramework #8739
base: main
Are you sure you want to change the base?
Conversation
d6cb976
to
999cfa6
Compare
999cfa6
to
22c1e96
Compare
src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/Application/DocumentStream.cs
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/PresentationUI/MS/Internal/Documents/SignatureResourceHelper.cs
Show resolved
Hide resolved
22c1e96
to
717cfa0
Compare
sb.AppendFormat(provider, "ContextColor {0} ", uriString); | ||
sb.AppendFormat(provider, "{1:R}{0}", separator, color.ScA); | ||
for (int i = 0; i < color.GetNativeColorValues().GetLength(0); ++i) | ||
sb.AppendFormat(provider, $"ContextColor {uriString} "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be replaced with sb.Append right ?
"<LinkTarget Name=\"{0}\" />", | ||
nameElement) | ||
); | ||
xmlWriter.WriteRaw($"<LinkTarget Name=\"{nameElement}\" />"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InvariantCulture missing here
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture, | ||
"{0}.fdseq", | ||
new object[] { contentKey }); | ||
uniqueUri = $"{contentKey}.fdseq"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InvariantCulture missing here
" xmlns:" + PrintSchemaPrefixes.xsd + "=\"" + PrintSchemaNamespaces.xsd + "\"" + | ||
" version=\"1\">" + | ||
"</" + PrintSchemaPrefixes.Framework + ":" + PrintSchemaTags.Framework.PrintTicketRoot + ">"; | ||
internal const string EmptyPrintTicket = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><{PrintSchemaPrefixes.Framework}:{PrintSchemaTags.Framework.PrintTicketRoot} xmlns:{PrintSchemaPrefixes.Framework}=\"{PrintSchemaNamespaces.Framework}\" xmlns:{PrintSchemaPrefixes.StandardKeywordSet}=\"{PrintSchemaNamespaces.StandardKeywordSet}\" xmlns:{PrintSchemaPrefixes.xsi}=\"{PrintSchemaNamespaces.xsi}\" xmlns:{PrintSchemaPrefixes.xsd}=\"{PrintSchemaNamespaces.xsd}\" version=\"1\"></{PrintSchemaPrefixes.Framework}:{PrintSchemaTags.Framework.PrintTicketRoot}>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use string.Concat or the original way here. IMO, this string is too long for using interpolation.
string resourceName = "PUIRMStatus" | ||
+ Enum.GetName(typeof(RightsManagementStatus), status) | ||
+ "BrushKey"; | ||
string resourceName = $"PUIRMStatus{Enum.GetName(status)}BrushKey"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right ? Enum.GetName ?
string resourceName = "PUISignatureStatus" | ||
+ Enum.GetName(typeof(SignatureStatus), sigStatus) | ||
+ "BrushKey"; | ||
string resourceName = $"PUISignatureStatus{Enum.GetName(sigStatus)}BrushKey"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum.GetName(typeof(SignatureStatus), sigStatus)
?
DisplayList.LeftPad(transparentCluster[i].DebugBounds, 0), | ||
DisplayList.LeftPad(transparentCluster[i].DebugPrimitives, 0), | ||
transparentCluster[i].DebugRasterize); | ||
Console.WriteLine($"Cluster {i + 1}: {DisplayList.LeftPad(transparentCluster[i].DebugBounds, 0)} {DisplayList.LeftPad(transparentCluster[i].DebugPrimitives, 0)} {transparentCluster[i].DebugRasterize}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interpolation is too long, can we revert this back as original ?
@@ -176,8 +176,7 @@ public CanvasImageableArea ImageableArea | |||
/// <returns>A string that represents this imageable size capability object.</returns> | |||
public override string ToString() | |||
{ | |||
return "ImageableSizeWidth=" + ImageableSizeWidth + ", ImageableSizeHeight=" + ImageableSizeHeight + " " + | |||
((ImageableArea != null) ? ImageableArea.ToString() : "[ImageableArea: null]"); | |||
return $"ImageableSizeWidth={ImageableSizeWidth}, ImageableSizeHeight={ImageableSizeHeight} {((ImageableArea != null) ? ImageableArea.ToString() : "[ImageableArea: null]")}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we split in two lines ? Too long interpolation string.
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"), | ||
errorMsg), | ||
"printTicket"); | ||
throw new ArgumentException($"{PrintSchemaTags.Framework.PrintTicketRoot} {PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed")} {errorMsg}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the previous way here. The current change results in too long interpolation. Same suggestion for the change below and FallbackPTProvider.cs
_addressTemplate, | ||
mailtoUri.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped), | ||
mailtoUri.GetComponents(UriComponents.Host, UriFormat.Unescaped)); | ||
address = $"{mailtoUri.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped)}@{mailtoUri.GetComponents(UriComponents.Host, UriFormat.Unescaped)}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we revert this back to the original way ? Same reasoning, too long string.
@halgab, can you take a look at the above PR and make the necessary changes ? |
Follow-up to #8519
Description
We replace as many manual string concatenations and string.Format with interpolated strings. This saves allocations in many instances, and makes for a more readable code.
Customer Impact
Less allocations
Regression
No
Testing
CI
Risk
Low. Most changes are automated using the IDE
Microsoft Reviewers: Open in CodeFlow