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

Prefer use of interpolated strings in PresentationUI and ReachFramework #8739

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void EnsureNotDisposed()
private void EnsureState(State requiredState)
{
if (InitializationState != requiredState)
throw new InvalidOperationException("InitializationState != " + requiredState.ToString());
throw new InvalidOperationException($"InitializationState != {requiredState}");
}


Expand Down
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)}";
Copy link
Member

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.

}

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 @@ -28,13 +28,13 @@ namespace MS.Internal.Documents.Application
/// Responsibility:
/// The class must hide the location and implemenation complexity of
/// performing simple logical operations needed by the system.
///
///
/// Design Comments:
/// The need for this is primarly driven from two factors:
///
///
/// - Package which does not allow use to discard changes
///
/// - RightsManagement where key changes make it impossible to edit a
///
/// - RightsManagement where key changes make it impossible to edit a
/// document in place
/// </remarks>
internal sealed class DocumentStream : StreamProxy, IDisposable
Expand Down Expand Up @@ -155,7 +155,7 @@ internal DocumentStream Copy(CriticalFileToken copiesToken)
}
}
// Since we have already closed the original file, we need to reopen it if we
// fail to copy the file or open the new file. After doing so, we rethrow the
// fail to copy the file or open the new file. After doing so, we rethrow the
// original exception so it can be handled at a higher level.
#pragma warning suppress 56500 // suppress PreSharp Warning 56500: Avoid `swallowing errors by catching non-specific exceptions..
catch
Expand Down Expand Up @@ -220,7 +220,7 @@ internal DocumentStream Copy(CriticalFileToken copiesToken)
/// <remarks>
/// We prefer to create the temporary file in the same location as the
/// source to inherit the folders attributes and security.
///
///
/// If we can not we will use a system generated file.
/// </remarks>
/// <param name="copyoriginal">When true we will copy the source file if
Expand Down Expand Up @@ -262,7 +262,7 @@ internal DocumentStream CreateTemporary(bool copyOriginal)
// Copy Data
if (copyOriginal)
{
// We use a native File.Copy if possible because this is
// We use a native File.Copy if possible because this is
// most performant. This is only possible if the source is file
// based.
if (isFileSource)
Expand Down Expand Up @@ -499,9 +499,9 @@ internal bool ReOpenWriteable()
/// <returns>False if the operation failed.</returns>
/// <remarks>
/// This method is inplace to work around issues with re-publishing
/// XpsDocuments into the same file. The intended use for the method is
/// XpsDocuments into the same file. The intended use for the method is
/// to logically allow in place editing for the user.
///
///
/// After use this object is unusable and should be disposed as the
/// temporary file is gone; it has become the original. In the event of an
/// error while swapping the file, the file no longer becomes the original,
Expand Down Expand Up @@ -588,7 +588,7 @@ internal bool SwapWithOriginal()
#pragma warning suppress 56500 // suppress PreSharp Warning 56500: Avoid `swallowing errors by catching non-specific exceptions..
catch
{
// TODO: 1603621 back out changes in case of failure
// TODO: 1603621 back out changes in case of failure
Trace.SafeWrite(
Trace.File,
"File attributes or permissions could not be set.");
Expand Down Expand Up @@ -666,7 +666,7 @@ internal bool DeleteOnClose
void IDisposable.Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
GC.SuppressFinalize(this);
}


Expand Down Expand Up @@ -735,7 +735,7 @@ protected override void Dispose(bool disposing)
/// <param name="temporary">The stream for the temporary file.</param>
/// <param name="tempToken">The file token for the temporary file.</param>
private void MakeTempFile(
bool inSameFolder,
bool inSameFolder,
out FileStream temporary,
out CriticalFileToken tempToken)
{
Expand Down Expand Up @@ -803,8 +803,10 @@ private void MakeTempFile(
#if DEBUG
Invariant.Assert(
((i != 3) || (temporary != null) || (inSameFolder)),
"Unable to create a temp file.\n"
+ "Unless IE Cache is read-only we have a defect.");
"""
Unable to create a temp file.
halgab marked this conversation as resolved.
Show resolved Hide resolved
Unless IE Cache is read-only we have a defect.
""");
#endif
}
}
Expand All @@ -829,17 +831,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 All @@ -849,19 +844,19 @@ private Uri MakeTemporaryFileName(bool inSameFolder, int generation)
/// <remarks>
/// Design is simple Source needs to be moved to Target ensuring
/// no data loss on errror.
///
///
/// If Source exists rename it (creating Backup)
/// Move Source to Target
/// If error occurs Move Backup to Source (resore from Backup)
/// If all was good (delete Backup)
///
///
/// This design incures trival I/O costs by using moves.
/// </remarks>
private void RobustFileMove()
{
string sourceFile = _xpsFileToken.Location.LocalPath;
string targetFile = _original._xpsFileToken.Location.LocalPath;
string backupFile = targetFile + ".bak";
string backupFile = $"{targetFile}.bak";

bool backupExists = false;
FileAttributes targetAttributes = FileAttributes.Normal;
Expand All @@ -888,7 +883,7 @@ private void RobustFileMove()
// Save the original file attributes so we can restore them if
// the temp file copy fails.
targetAttributes = File.GetAttributes(targetFile);
File.Move(targetFile, backupFile);
File.Move(targetFile, backupFile);

Trace.SafeWrite(
Trace.File,
Expand All @@ -910,7 +905,7 @@ private void RobustFileMove()
Trace.File,
"Moved(Saved) {0} as {1}.",
sourceFile,
targetFile);
targetFile);
}
catch
{
Expand All @@ -920,7 +915,7 @@ private void RobustFileMove()
if (backupExists)
{
// restore original on failure
File.Move(backupFile, targetFile);
File.Move(backupFile, targetFile);
Trace.SafeWrite(
Trace.File,
"Restored {0} from {1}, due to exception.",
Expand All @@ -937,8 +932,8 @@ private void RobustFileMove()
{
// Try to delete the backup file
if (backupExists)
{
File.Delete(backupFile);
{
File.Delete(backupFile);
backupExists = false;
Trace.SafeWrite(
Trace.File,
Expand All @@ -955,7 +950,7 @@ private void RobustFileMove()
"Unable to remove backup {0}.\n{1}",
backupFile,
e);
}
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static bool ShowSaveFileDialog(ref CriticalFileToken fileToken)
string extension = SR.FileManagementSaveExt;

Trace.SafeWrite(Trace.File, "Showing SafeFileDialog.");

bool result = false;

SaveFileDialog save = new SaveFileDialog();
Expand Down Expand Up @@ -85,10 +85,10 @@ internal static bool ShowSaveFileDialog(ref CriticalFileToken fileToken)
// gets up to homework.386, then the dialog would just pass it through as
// is, requiring us to append the extension here.
if (!extension.Equals(
Path.GetExtension(filePath),
Path.GetExtension(filePath),
StringComparison.OrdinalIgnoreCase))
{
filePath = filePath + extension;
filePath += extension;
}

Uri file = new Uri(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private RightsManagementResourceHelper()
internal static DocumentStatusResources GetDocumentLevelResources(RightsManagementStatus status)
{
DocumentStatusResources docStatusResources = new DocumentStatusResources();

// Set appropriate Text and ToolTip values.
switch (status)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ internal static string GetCredentialManagementResources(RightsManagementUser use
case (AuthenticationType.Windows):
accountName = String.Format(
CultureInfo.CurrentCulture,
SR.RMCredManagementWindowsAccount,
SR.RMCredManagementWindowsAccount,
user.Name);
break;
case (AuthenticationType.Passport):
Expand Down Expand Up @@ -137,9 +137,7 @@ private static DrawingBrush GetDrawingBrushFromStatus(RightsManagementStatus sta
if (_brushResources[index] == null)
{
// Determine resource name.
string resourceName = "PUIRMStatus"
+ Enum.GetName(typeof(RightsManagementStatus), status)
+ "BrushKey";
string resourceName = $"PUIRMStatus{Enum.GetName(status)}BrushKey";
Copy link
Member

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 ?


// Acquire reference to the brush.
object resource = _frameworkElement.FindResource(
Expand Down
Loading
Loading