Skip to content

Commit

Permalink
Use interpolated strings in more places
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/runtime@dfd618d
  • Loading branch information
stephentoub committed Jul 13, 2021
1 parent 40218a6 commit 5fd2890
Show file tree
Hide file tree
Showing 27 changed files with 42 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/Brush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected virtual void Dispose(bool disposing)
#endif
Gdip.GdipDeleteBrush(new HandleRef(this, _nativeBrush));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsSecurityOrCriticalException(ex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeletePath(new HandleRef(this, _nativePath));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeletePathIter(new HandleRef(this, nativeIter));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override bool ReleaseHandle()
{
handle = IntPtr.Zero;
}
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
}
return status == Gdip.Ok;
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/Font.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void CreateFont(string familyName, float emSize, FontStyle style, Graphi
int status = Gdip.GdipCreateFont(new HandleRef(this, family.NativeFamily), emSize, style, unit, out _nativeFont);

if (status == Gdip.FontStyleNotFound)
throw new ArgumentException($"Style {style.ToString()} isn't supported by font {familyName}.");
throw new ArgumentException($"Style {style} isn't supported by font {familyName}.");

Gdip.CheckStatus(status);
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeleteFont(new HandleRef(this, _nativeFont));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsCriticalException(ex))
Expand Down
6 changes: 4 additions & 2 deletions src/System.Drawing.Common/src/System/Drawing/FontConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina

ValueStringBuilder sb = default;
sb.Append(font.Name);
sb.Append(culture.TextInfo.ListSeparator[0] + " ");
sb.Append(culture.TextInfo.ListSeparator[0]);
sb.Append(" ");
sb.Append(font.Size.ToString(culture.NumberFormat));

switch (font.Unit)
Expand Down Expand Up @@ -79,7 +80,8 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina

if (font.Style != FontStyle.Regular)
{
sb.Append(culture.TextInfo.ListSeparator[0] + " style=");
sb.Append(culture.TextInfo.ListSeparator[0]);
sb.Append(" style=");
sb.Append(font.Style.ToString());
}

Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/FontFamily.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeleteFontFamily(new HandleRef(this, _nativeFamily));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsCriticalException(ex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void Dispose(bool disposing)
Gdip.GdipDeleteGraphics(new HandleRef(this, NativeGraphics));

#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsSecurityOrCriticalException(ex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected virtual void Dispose(bool disposing)
#endif
Gdip.GdipDisposeImage(new HandleRef(this, nativeImage));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override string ToString()
if (this == s_time) return "Time";
if (this == s_resolution) return "Resolution";
if (this == s_page) return "Page";
return "[FrameDimension: " + _guid + "]";
return $"[FrameDimension: {_guid}]";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDisposeImageAttributes(new HandleRef(this, nativeImageAttributes));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public override string ToString()
if (this.Guid == s_tiff.Guid) return "Tiff";
if (this.Guid == s_exif.Guid) return "Exif";
if (this.Guid == s_icon.Guid) return "Icon";
return "[ImageFormat: " + _guid + "]";
return $"[ImageFormat: {_guid}]";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static void Add(ISystemColorTracker obj)
list[index] = new WeakReference(obj);
else
{
Debug.Assert(list[index].Target == null, "Trying to reuse a weak reference that isn't broken yet: list[" + index + "], length =" + list.Length);
Debug.Assert(list[index].Target == null, $"Trying to reuse a weak reference that isn't broken yet: list[{index}], length = {list.Length}");
list[index].Target = obj;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/Pen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeletePen(new HandleRef(this, NativePen));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsSecurityOrCriticalException(ex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ public override bool Equals([NotNullWhen(true)] object? obj)
/// <summary>
/// Provides some interesting information for the Margins in String form.
/// </summary>
public override string ToString()
{
return "[Margins"
+ " Left=" + Left.ToString(CultureInfo.InvariantCulture)
+ " Right=" + Right.ToString(CultureInfo.InvariantCulture)
+ " Top=" + Top.ToString(CultureInfo.InvariantCulture)
+ " Bottom=" + Bottom.ToString(CultureInfo.InvariantCulture)
+ "]";
}
public override string ToString() => $"[Margins Left={Left} Right={Right} Top={Top} Bottom={Bottom}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ public void SetHdevmode(IntPtr hdevmode)
throw new NotImplementedException();
}

public override string ToString()
{
return $"[{nameof(PageSettings)}: {nameof(Color)}={color}, {nameof(Landscape)}={landscape}, {nameof(Margins)}={margins}, {nameof(PaperSize)}={paperSize}, {nameof(PaperSource)}={paperSource}, {nameof(PrinterResolution)}={printerResolution}]";
}
public override string ToString() =>
$"[{nameof(PageSettings)}: {nameof(Color)}={color}, {nameof(Landscape)}={landscape}, {nameof(Margins)}={margins}, {nameof(PaperSize)}={paperSize}, {nameof(PaperSource)}={paperSource}, {nameof(PrinterResolution)}={printerResolution}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,16 +536,7 @@ public void SetHdevmode(IntPtr hdevmode)
/// <summary>
/// Provides some interesting information about the PageSettings in String form.
/// </summary>
public override string ToString()
{
return "[PageSettings:"
+ " Color=" + Color.ToString()
+ ", Landscape=" + Landscape.ToString()
+ ", Margins=" + Margins.ToString()
+ ", PaperSize=" + PaperSize.ToString()
+ ", PaperSource=" + PaperSource.ToString()
+ ", PrinterResolution=" + PrinterResolution.ToString()
+ "]";
}
public override string ToString() =>
$"[{nameof(PageSettings)}: Color={Color}, Landscape={Landscape}, Margins={Margins}, PaperSize={PaperSize}, PaperSource={PaperSource}, PrinterResolution={PrinterResolution}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ public int Width
/// <summary>
/// Provides some interesting information about the PaperSize in String form.
/// </summary>
public override string ToString()
{
return "[PaperSize " + PaperName
+ " Kind=" + Kind.ToString()
+ " Height=" + Height.ToString(CultureInfo.InvariantCulture)
+ " Width=" + Width.ToString(CultureInfo.InvariantCulture)
+ "]";
}
public override string ToString() => $"[PaperSize {PaperName} Kind={Kind.ToString()} Height={Height.ToString(CultureInfo.InvariantCulture)} Width={Width.ToString(CultureInfo.InvariantCulture)}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public string SourceName
/// <summary>
/// Provides some interesting information about the PaperSource in String form.
/// </summary>
public override string ToString()
{
return "[PaperSource " + SourceName
+ " Kind=" + Kind.ToString()
+ "]";
}
public override string ToString() => $"[PaperSource {SourceName} Kind={Kind}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ public void Print()
PrintController.OnEndPrint(this, printArgs);
}

public override string ToString()
{
return "[PrintDocument " + this.DocumentName + "]";
}
public override string ToString() => $"[PrintDocument {this.DocumentName}]";

// events
protected virtual void OnBeginPrint(PrintEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ public void Print()
/// <summary>
/// Provides some interesting information about the PrintDocument in String form.
/// </summary>
public override string ToString()
{
return "[PrintDocument " + DocumentName + "]";
}
public override string ToString() => $"[PrintDocument {DocumentName}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,7 @@ public void SetHdevnames(IntPtr hdevnames)
throw new NotImplementedException();
}

public override string ToString()
{
return "Printer [PrinterSettings " + printer_name + " Copies=" + copies + " Collate=" + collate
+ " Duplex=" + can_duplex + " FromPage=" + from_page + " LandscapeAngle=" + landscape_angle
+ " MaximumCopies=" + maximum_copies + " OutputPort=" + " ToPage=" + to_page + "]";

}
public override string ToString() => $"Printer [PrinterSettings {printer_name} Copies={copies} Collate={collate} Duplex={can_duplex} FromPage={from_page} LandscapeAngle={landscape_angle} MaximumCopies={maximum_copies} OutputPort= ToPage={to_page}]";

// Public subclasses
#region Public Subclasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,16 +1258,16 @@ public override string ToString()
{
string printerName = PrinterName;
return "[PrinterSettings "
+ printerName
+ " Copies=" + Copies.ToString(CultureInfo.InvariantCulture)
+ " Collate=" + Collate.ToString(CultureInfo.InvariantCulture)
+ " Duplex=" + Duplex.ToString()
+ " FromPage=" + FromPage.ToString(CultureInfo.InvariantCulture)
+ " LandscapeAngle=" + LandscapeAngle.ToString(CultureInfo.InvariantCulture)
+ " MaximumCopies=" + MaximumCopies.ToString(CultureInfo.InvariantCulture)
+ " OutputPort=" + OutputPort.ToString(CultureInfo.InvariantCulture)
+ " ToPage=" + ToPage.ToString(CultureInfo.InvariantCulture)
+ "]";
+ printerName
+ " Copies=" + Copies.ToString(CultureInfo.InvariantCulture)
+ " Collate=" + Collate.ToString(CultureInfo.InvariantCulture)
+ " Duplex=" + Duplex.ToString()
+ " FromPage=" + FromPage.ToString(CultureInfo.InvariantCulture)
+ " LandscapeAngle=" + LandscapeAngle.ToString(CultureInfo.InvariantCulture)
+ " MaximumCopies=" + MaximumCopies.ToString(CultureInfo.InvariantCulture)
+ " OutputPort=" + OutputPort.ToString(CultureInfo.InvariantCulture)
+ " ToPage=" + ToPage.ToString(CultureInfo.InvariantCulture)
+ "]";
}

// Write null terminated string, return length of string in characters (including null)
Expand Down
2 changes: 1 addition & 1 deletion src/System.Drawing.Common/src/System/Drawing/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeleteRegion(new HandleRef(this, NativeRegion));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsSecurityOrCriticalException(ex))
Expand Down
7 changes: 2 additions & 5 deletions src/System.Drawing.Common/src/System/Drawing/StringFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void Dispose(bool disposing)
#endif
Gdip.GdipDeleteStringFormat(new HandleRef(this, nativeFormat));
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex)
Expand Down Expand Up @@ -442,9 +442,6 @@ internal int GetMeasurableCharacterRangeCount()
/// <summary>
/// Converts this <see cref='StringFormat'/> to a human-readable string.
/// </summary>
public override string ToString()
{
return "[StringFormat, FormatFlags=" + FormatFlags.ToString() + "]";
}
public override string ToString() => $"[StringFormat, FormatFlags={FormatFlags.ToString()}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override void Dispose(bool disposing)
#endif
Gdip.GdipDeletePrivateFontCollection(ref _nativeFontCollection);
#if DEBUG
Debug.Assert(status == Gdip.Ok, "GDI+ returned an error status: " + status.ToString(CultureInfo.InvariantCulture));
Debug.Assert(status == Gdip.Ok, $"GDI+ returned an error status: {status.ToString(CultureInfo.InvariantCulture)}");
#endif
}
catch (Exception ex) when (!ClientUtils.IsSecurityOrCriticalException(ex))
Expand Down

0 comments on commit 5fd2890

Please sign in to comment.