From d25e794bfd7c6c31247450cb48c4c8c561e771c1 Mon Sep 17 00:00:00 2001 From: Jeremy Kuhne Date: Sat, 17 Mar 2018 04:15:24 -0700 Subject: [PATCH] Use Win32Marshal from CoreLib shared code (dotnet/corefx#28161) * Use Win32Marshal from CoreLib shared code Fix hr issue caught by Common.Tests. * Move string condition inside exception arguments Signed-off-by: dotnet-bot-corefx-mirror --- src/mscorlib/shared/System/IO/Win32Marshal.cs | 32 ++++++++++++--------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/mscorlib/shared/System/IO/Win32Marshal.cs b/src/mscorlib/shared/System/IO/Win32Marshal.cs index 060f823..7888d8d 100644 --- a/src/mscorlib/shared/System/IO/Win32Marshal.cs +++ b/src/mscorlib/shared/System/IO/Win32Marshal.cs @@ -27,29 +27,25 @@ namespace System.IO switch (errorCode) { case Interop.Errors.ERROR_FILE_NOT_FOUND: - return string.IsNullOrEmpty(path) - ? new FileNotFoundException(SR.IO_FileNotFound) - : new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, path), path); + return new FileNotFoundException( + string.IsNullOrEmpty(path) ? SR.IO_FileNotFound : SR.Format(SR.IO_FileNotFound_FileName, path), path); case Interop.Errors.ERROR_PATH_NOT_FOUND: - return string.IsNullOrEmpty(path) - ? new DirectoryNotFoundException(SR.IO_PathNotFound_NoPathName) - : new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, path)); + return new DirectoryNotFoundException( + string.IsNullOrEmpty(path) ? SR.IO_PathNotFound_NoPathName : SR.Format(SR.IO_PathNotFound_Path, path)); case Interop.Errors.ERROR_ACCESS_DENIED: - return string.IsNullOrEmpty(path) - ? new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName) - : new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path)); + return new UnauthorizedAccessException( + string.IsNullOrEmpty(path) ? SR.UnauthorizedAccess_IODenied_NoPathName : SR.Format(SR.UnauthorizedAccess_IODenied_Path, path)); case Interop.Errors.ERROR_ALREADY_EXISTS: if (string.IsNullOrEmpty(path)) goto default; return new IOException(SR.Format(SR.IO_AlreadyExists_Name, path), MakeHRFromErrorCode(errorCode)); case Interop.Errors.ERROR_FILENAME_EXCED_RANGE: - return string.IsNullOrEmpty(path) - ? new PathTooLongException(SR.IO_PathTooLong) - : new PathTooLongException(SR.Format(SR.IO_PathTooLong_Path, path)); + return new PathTooLongException( + string.IsNullOrEmpty(path) ? SR.IO_PathTooLong : SR.Format(SR.IO_PathTooLong_Path, path)); case Interop.Errors.ERROR_SHARING_VIOLATION: - return string.IsNullOrEmpty(path) - ? new IOException(SR.IO_SharingViolation_NoFileName, MakeHRFromErrorCode(errorCode)) - : new IOException(SR.Format(SR.IO_SharingViolation_File, path), MakeHRFromErrorCode(errorCode)); + return new IOException( + string.IsNullOrEmpty(path) ? SR.IO_SharingViolation_NoFileName : SR.Format(SR.IO_SharingViolation_File, path), + MakeHRFromErrorCode(errorCode)); case Interop.Errors.ERROR_FILE_EXISTS: if (string.IsNullOrEmpty(path)) goto default; @@ -58,9 +54,9 @@ namespace System.IO return new OperationCanceledException(); case Interop.Errors.ERROR_INVALID_PARAMETER: default: - return string.IsNullOrEmpty(path) - ? new IOException(GetMessage(errorCode), MakeHRFromErrorCode(errorCode)) - : new IOException($"{GetMessage(errorCode)} : '{path}'"); + return new IOException( + string.IsNullOrEmpty(path) ? GetMessage(errorCode) : $"{GetMessage(errorCode)} : '{path}'", + MakeHRFromErrorCode(errorCode)); } } -- 2.7.4