Skip to content

Commit

Permalink
string.Format evictions
Browse files Browse the repository at this point in the history
  • Loading branch information
halgab committed Jan 28, 2024
1 parent 94d3cc0 commit be3b317
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ internal static string GetEmailAddressFromMailtoUri(Uri mailtoUri)
if (IsMailtoUri(mailtoUri))
{
// Create the address from the URI
address = string.Format(
CultureInfo.CurrentCulture,
_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)}";
}

return address;
Expand All @@ -75,45 +71,17 @@ internal static Uri GenerateMailtoUri(string address)
// Add the scheme to the e-mail address to form a URI object
if (!string.IsNullOrEmpty(address))
{
return new Uri(string.Format(
CultureInfo.CurrentCulture,
_mailtoUriTemplate,
Uri.UriSchemeMailto,
_mailtoSchemeDelimiter,
address));
// The delimiter between the scheme and the address in a mailto URI.
// We unfortunately cannot use the Uri class SchemeDelimiter because
// it is by default set to "://", which makes mailto: URIs generated
// look like "mailto://user@host", which in turn cannot be parsed
// properly by this class.
return new Uri($"{Uri.UriSchemeMailto}:{address}");
}

return null;
}

#endregion Internal Methods

#region Private Fields
//--------------------------------------------------------------------------
// Private Fields
//--------------------------------------------------------------------------

/// <summary>
/// The template for an e-mail address with a user name and a host.
/// </summary>
private const string _addressTemplate = "{0}@{1}";

/// <summary>
/// The template for a mailto scheme URI with the mailto scheme and an
/// address.
/// </summary>
private const string _mailtoUriTemplate = "{0}{1}{2}";

/// <summary>
/// The delimiter between the scheme and the address in a mailto URI.
/// We unfortunately cannot use the Uri class SchemeDelimiter because
/// it is by default set to "://", which makes mailto: URIs generated
/// look like "mailto://user@host", whicn in turn cannot be parsed
/// properly by this class.
/// </summary>
private const string _mailtoSchemeDelimiter = ":";

#endregion Private Fields

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ private void AssertIfNotDisposed()
{
Invariant.Assert(
_isDisposed,
string.Format(
System.Globalization.CultureInfo.CurrentCulture,
"{0} was not disposed.",
this));
$"{this} was not disposed.");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,17 +829,10 @@ private Uri MakeTemporaryFileName(bool inSameFolder, int generation)
file = this.GetHashCode().ToString(CultureInfo.InvariantCulture);
}

string temp = string.Format(
CultureInfo.CurrentCulture,
"{0}{1}~{2}{3}{4}",
Path.GetDirectoryName(path),
Path.DirectorySeparatorChar,
generation == 0 ?
string.Empty :
generation.ToString(CultureInfo.CurrentCulture)
+ "~",
file,
XpsFileExtension);
string temp = generation == 0
? $"{Path.GetDirectoryName(path)}{Path.DirectorySeparatorChar}~{file}{XpsFileExtension}"
: $"{Path.GetDirectoryName(path)}{Path.DirectorySeparatorChar}~{generation}~{file}{XpsFileExtension}";

return new Uri(temp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ internal static class SignatureResourceHelper
sigStatus = SignatureStatus.Invalid;
}

string resourceName = string.Format(
CultureInfo.InvariantCulture,
@"{0}_{1}x{2}",
sigStatus.ToString(),
height,
width);
string resourceName = $@"{sigStatus}_{height}x{width}";
return (Drawing.Image)Resources.ResourceManager.GetObject(resourceName);
}

Expand Down Expand Up @@ -323,13 +318,7 @@ private static string GetSignatureSummaryMessage(SignatureStatus sigStatus, Cert
/// <returns>The short date or 'none' if the value was null.</returns>
private static string GetFormattedDate(Nullable<DateTime> date)
{
string none = SR.SignatureResourceHelperNone;

return date == null ?
none :
String.Format(
CultureInfo.CurrentCulture,
((DateTime)date).ToShortDateString());
return date?.ToShortDateString() ?? SR.SignatureResourceHelperNone;
}
#endregion Private Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,7 @@ IList<String> linkTargetStream
xmlWriter.WriteRaw ("<PageContent.LinkTargets>");
foreach (String nameElement in linkTargetStream)
{
xmlWriter.WriteRaw (String.Format(
System.Globalization.CultureInfo.InvariantCulture,
"<LinkTarget Name=\"{0}\" />",
nameElement)
);
xmlWriter.WriteRaw($"<LinkTarget Name=\"{nameElement}\" />");
}
xmlWriter.WriteRaw ("</PageContent.LinkTargets>");
}
Expand Down
44 changes: 17 additions & 27 deletions src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,59 +1124,49 @@ ContentType contentType

if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.DocumentSequenceContentType))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"{0}.fdseq",
new object[] { contentKey });
uniqueUri = $"{contentKey}.fdseq";
}
else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.FixedDocumentContentType))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Documents/{0}/FixedDocument.fdoc",
new object[] { counter });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Documents/{counter}/FixedDocument.fdoc");
string pageContentKey = GetContentCounterKey(XpsS0Markup.FixedPageContentType);
_contentTypes[pageContentKey] = 1;
}
else if (contentType.AreTypeAndSubTypeEqual(XpsS0Markup.FixedPageContentType))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Documents/{0}/Pages/{1}.fpage",
new object[] { docCounter, counter });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Documents/{docCounter}/Pages/{counter}.fpage");
}
else if (contentKey.Equals("Dictionary", StringComparison.OrdinalIgnoreCase))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Resources/{0}.dict",
new object[] { uniqueName });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Resources/{uniqueName}.dict");
}
else if (contentKey.Equals("Font", StringComparison.OrdinalIgnoreCase))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Resources/{0}.ttf",
new object[] { uniqueName });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Resources/{uniqueName}.ttf");
}
else if (contentKey.Equals("ColorContext", StringComparison.OrdinalIgnoreCase))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Resources/{0}.icc",
new object[] { uniqueName });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Resources/{uniqueName}.icc");
}
else if (contentKey.Equals("ResourceDictionary", StringComparison.OrdinalIgnoreCase))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Resources/{0}.dict",
new object[] { uniqueName });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Resources/{uniqueName}.dict");
}
else if (contentKey.Equals("Image", StringComparison.OrdinalIgnoreCase))
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/Resources/{0}.{1}",
new object[] { uniqueName, LookupImageExtension(contentType) });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/Resources/{uniqueName}.{LookupImageExtension(contentType)}");
}
else
{
uniqueUri = String.Format(System.Globalization.CultureInfo.InvariantCulture,
"/{0}s/{0}_{1}.xaml",
new object[] { contentKey, counter });
uniqueUri = string.Create(System.Globalization.CultureInfo.InvariantCulture,
$"/{contentKey}s/{contentKey}_{counter}.xaml");
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,8 @@ public override MemoryStream GetPrintCapabilities(MemoryStream printTicket)
catch (XmlException xmlException)
{
throw new ArgumentException(
String.Format(
CultureInfo.CurrentCulture,
"{0} {1} {2}",
PrintSchemaTags.Framework.PrintTicketRoot,
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
xmlException.Message),
"printTicket",
$"{PrintSchemaTags.Framework.PrintTicketRoot} {PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed")} {xmlException.Message}",
nameof(printTicket),
xmlException);
}

Expand Down Expand Up @@ -383,21 +378,15 @@ private string OemDriverNamespace
{
if (this._printTicketNamespace == null)
{
string deviceNamepace = string.Format(
string deviceNamepace = string.Create(
CultureInfo.InvariantCulture,
DeviceNamespaceFormat,
BuildInfo.WCP_VERSION_SUFFIX,
this._driverName,
this._driverVersion);
$"http://schemas.microsoft.com/windows/printing/oemdriverpt/netfx{BuildInfo.WCP_VERSION_SUFFIX}/{_driverName}/v{_driverVersion}");

if (!Uri.IsWellFormedUriString(deviceNamepace, UriKind.Absolute))
{
deviceNamepace = string.Format(
deviceNamepace = string.Create(
CultureInfo.InvariantCulture,
DeviceNamespaceFormat,
BuildInfo.WCP_VERSION_SUFFIX,
Uri.EscapeDataString(this._driverName),
this._driverVersion);
$"http://schemas.microsoft.com/windows/printing/oemdriverpt/netfx{BuildInfo.WCP_VERSION_SUFFIX}/{Uri.EscapeDataString(_driverName)}/v{_driverVersion}");
}

this._printTicketNamespace = deviceNamepace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,8 @@ public override MemoryStream GetPrintCapabilities(MemoryStream printTicket)

if (hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT)
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
"{0} {1} {2}",
PrintSchemaTags.Framework.PrintTicketRoot,
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
errorMsg),
"printTicket");
throw new ArgumentException($"{PrintSchemaTags.Framework.PrintTicketRoot} {PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed")} {errorMsg}",
nameof(printTicket));
}
else
{
Expand Down Expand Up @@ -343,11 +339,7 @@ public override MemoryStream GetPrintCapabilities(MemoryStream printTicket)
if ((hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT) ||
(hResult == (uint)NativeErrorCode.E_DELTA_PRINTTICKET_FORMAT))
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
"{0} {1} {2}",
PrintSchemaTags.Framework.PrintTicketRoot,
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
errorMsg),
throw new ArgumentException($"{PrintSchemaTags.Framework.PrintTicketRoot} {PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed")} {errorMsg}",
(hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT) ? "basePrintTicket" : "deltaPrintTicket");
}
else
Expand Down Expand Up @@ -504,12 +496,8 @@ public override MemoryStream GetPrintCapabilities(MemoryStream printTicket)
if ((hResult == (uint)NativeErrorCode.E_XML_INVALID) ||
(hResult == (uint)NativeErrorCode.E_PRINTTICKET_FORMAT))
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
"{0} {1} {2}",
PrintSchemaTags.Framework.PrintTicketRoot,
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
errorMsg),
"printTicket");
throw new ArgumentException($"{PrintSchemaTags.Framework.PrintTicketRoot} {PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed")} {errorMsg}",
nameof(printTicket));
}

throw new PrintQueueException((int)hResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void WriteJobInputBinFeature(IList<short> bins, IList<string> binDisplayN
}
else
{
optionLocalName = string.Format(CultureInfo.InvariantCulture, "User{0:0000000000}", bins[i]);
optionLocalName = string.Create(CultureInfo.InvariantCulture, $"User{bins[i]:0000000000}");
string optionDisplayName = (i < binDisplayNames.Count) ? binDisplayNames[i] : null;
WriteStartOption(this._privateNamespace, optionLocalName, optionDisplayName, "None");
WriteEndOption();
Expand Down Expand Up @@ -416,7 +416,7 @@ out pskMaterial
}
else
{
optionLocalName = string.Format(CultureInfo.InvariantCulture, "User{0:0000000000}", mediaTypes[i]);
optionLocalName = string.Create(CultureInfo.InvariantCulture, $"User{mediaTypes[i]:0000000000}");
optionDisplayName = (i < mediaTypeDisplayNames.Count) ? mediaTypeDisplayNames[i] : null;
pskFrontCoating = null;
pskBackCoating = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,7 @@ public static DevMode TryGetEmbeddedDevMode(InternalPrintTicket ticket, string o
XPathNavigator docNavigator = ticket.XmlDoc.DocumentElement.CreateNavigator();
if (docNavigator != null)
{
string xPathString = string.Format(
System.Globalization.CultureInfo.InvariantCulture,
@"{0}:PrintTicket/{0}:ParameterInit[@name='{1}:PageDevmodeSnapshot']/{0}:Value",
psfPrefix,
oemDriverPrefix
);
string xPathString = $@"{psfPrefix}:PrintTicket/{psfPrefix}:ParameterInit[@name='{oemDriverPrefix}:PageDevmodeSnapshot']/{psfPrefix}:Value";

XPathNavigator node = docNavigator.SelectSingleNode(xPathString, ticket.NamespaceManager);
if (node != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,7 @@ internal static FormatException NewPrintCapFormatException(string detailMsg)
/// <returns>the new FormatException instance</returns>
internal static FormatException NewPrintCapFormatException(string detailMsg, Exception innerException)
{
return new FormatException(String.Format(CultureInfo.CurrentCulture,
"{0} {1} {2}",
PrintSchemaTags.Framework.PrintCapRoot,
PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
detailMsg),
return new FormatException($"{PrintSchemaTags.Framework.PrintCapRoot} {PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed")} {detailMsg}",
innerException);
}

Expand Down Expand Up @@ -527,4 +523,4 @@ private void PostBuildProcessing()

#endregion Private Fields
}
}
}
Loading

0 comments on commit be3b317

Please sign in to comment.