Use Win32Marshal from CoreLib shared code (dotnet/corefx#28161)
authorJeremy Kuhne <jeremy.kuhne@microsoft.com>
Sat, 17 Mar 2018 11:15:24 +0000 (04:15 -0700)
committerStephen Toub <stoub@microsoft.com>
Sat, 17 Mar 2018 16:43:02 +0000 (12:43 -0400)
* 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 <dotnet-bot@microsoft.com>
src/mscorlib/shared/System/IO/Win32Marshal.cs

index 060f823..7888d8d 100644 (file)
@@ -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));
             }
         }