Skip to content

Commit 95d9eb0

Browse files
committed
refactor: invert if statement; remove else
1 parent 756d0b7 commit 95d9eb0

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

deadlock-dotnet-sdk/Domain/SafeFileHandleEx.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,22 +363,18 @@ public unsafe (string? v, Exception? ex) FileNameInfo
363363
int bufferLength = (int)(fni.FileNameLength + Marshal.SizeOf(fni));
364364
using SafeBuffer<FILE_NAME_INFO> safeBuffer = new(numBytes: (nuint)bufferLength);
365365

366-
if (GetFileInformationByHandleEx(this, FILE_INFO_BY_HANDLE_CLASS.FileNameInfo, (FILE_NAME_INFO*)safeBuffer.DangerousGetHandle(), (uint)bufferLength))
367-
{
368-
UNICODE_STRING str = new()
369-
{
370-
Buffer = new PWSTR((char*)safeBuffer.DangerousGetHandle()),
371-
Length = (ushort)fni.FileNameLength,
372-
MaximumLength = (ushort)bufferLength
373-
};
366+
if (!GetFileInformationByHandleEx(this, FILE_INFO_BY_HANDLE_CLASS.FileNameInfo, (FILE_NAME_INFO*)safeBuffer.DangerousGetHandle(), (uint)bufferLength))
367+
return fileNameInfo = (null, new Exception(errFailedMsg + "GetFileInformationByHandleEx encountered an error.", new Win32Exception()));
374368

375-
/* The string conversion copies the data to a new string in the managed heap before freeing safeBuffer and leaving this context. */
376-
return fileNameInfo = ((string)str, null);
377-
}
378-
else
369+
UNICODE_STRING str = new()
379370
{
380-
return fileNameInfo = (null, new Exception(errFailedMsg + "GetFileInformationByHandleEx encountered an error.", new Win32Exception()));
381-
}
371+
Buffer = new PWSTR((char*)safeBuffer.DangerousGetHandle()),
372+
Length = (ushort)fni.FileNameLength,
373+
MaximumLength = (ushort)bufferLength
374+
};
375+
376+
/* The string conversion copies the data to a new string in the managed heap before freeing safeBuffer and leaving this context. */
377+
return fileNameInfo = ((string)str, null);
382378
}
383379
else
384380
{

0 commit comments

Comments
 (0)