Skip to content

Commit

Permalink
Fixed code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jun 7, 2024
1 parent 6c5308a commit 723d45c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
9 changes: 8 additions & 1 deletion src/Elmah.Io.HResults/HResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
/// </summary>
public class HResult
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private HResult()
{
// Only the Parse method should ever create a new HResult
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

/// <summary>
/// Parse an integer to a HResult. The method will (unless an exception is thrown) always return a result.
/// </summary>
Expand All @@ -15,7 +22,7 @@ public static HResult Parse(int i)
hresult.IsFailure = isFailure;
var facility = (i & 0x7FFF0000) >> 16;
hresult.Facility = facility.ToFacility();
hresult.Hex = $"0x{i.ToString("X8")}";
hresult.Hex = $"0x{i:X8}";
var code = (i & 0xFFFF);
hresult.Code = code.ToCode(isFailure, facility);
return hresult;
Expand Down
65 changes: 32 additions & 33 deletions src/Elmah.Io.HResults/IntExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,39 @@ internal static Facility ToFacility(this int facility)
var resolver = facilityResolvers.Find(fr => fr.Identifier == facility);
if (resolver != null) return resolver.Facility();

switch (facility)
return facility switch
{

case 10: return new Facility(facility, "FACILITY_CONTROL");
case 12: return new Facility(facility, "FACILITY_INTERNET");
case 14: return new Facility(facility, "FACILITY_MSMQ");
case 18: return new Facility(facility, "FACILITY_AAF");
case 20: return new Facility(facility, "FACILITY_ACS");
case 21: return new Facility(facility, "FACILITY_DPLAY");
case 22: return new Facility(facility, "FACILITY_UMI");
case 23: return new Facility(facility, "FACILITY_SXS");
case 24: return new Facility(facility, "FACILITY_WINDOWS_CE");
case 25: return new Facility(facility, "FACILITY_HTTP");
case 26: return new Facility(facility, "FACILITY_USERMODE_COMMONLOG");
case 32: return new Facility(facility, "FACILITY_BACKGROUNDCOPY");
case 33: return new Facility(facility, "FACILITY_CONFIGURATION");
case 34: return new Facility(facility, "FACILITY_STATE_MANAGEMENT");
case 35: return new Facility(facility, "FACILITY_METADIRECTORY");
case 36: return new Facility(facility, "FACILITY_WINDOWSUPDATE");
case 37: return new Facility(facility, "FACILITY_DIRECTORYSERVICE");
case 39: return new Facility(facility, "FACILITY_SHELL");
case 51: return new Facility(facility, "FACILITY_WINRM");
case 53: return new Facility(facility, "FACILITY_USERMODE_HYPERVISOR");
case 54: return new Facility(facility, "FACILITY_CMI");
case 55: return new Facility(facility, "FACILITY_USERMODE_VIRTUALIZATION");
case 56: return new Facility(facility, "FACILITY_USERMODE_VOLMGR");
case 57: return new Facility(facility, "FACILITY_BCD");
case 58: return new Facility(facility, "FACILITY_USERMODE_VHD");
case 60: return new Facility(facility, "FACILITY_SDIAG");
case 61: return new Facility(facility, "FACILITY_WEBSERVICES");
case 80: return new Facility(facility, "FACILITY_WINDOWS_DEFENDER");
case 81: return new Facility(facility, "FACILITY_OPC");
default: return new Facility(facility, $"{facility}", isMatch: false);
}
10 => new Facility(facility, "FACILITY_CONTROL"),
12 => new Facility(facility, "FACILITY_INTERNET"),
14 => new Facility(facility, "FACILITY_MSMQ"),
18 => new Facility(facility, "FACILITY_AAF"),
20 => new Facility(facility, "FACILITY_ACS"),
21 => new Facility(facility, "FACILITY_DPLAY"),
22 => new Facility(facility, "FACILITY_UMI"),
23 => new Facility(facility, "FACILITY_SXS"),
24 => new Facility(facility, "FACILITY_WINDOWS_CE"),
25 => new Facility(facility, "FACILITY_HTTP"),
26 => new Facility(facility, "FACILITY_USERMODE_COMMONLOG"),
32 => new Facility(facility, "FACILITY_BACKGROUNDCOPY"),
33 => new Facility(facility, "FACILITY_CONFIGURATION"),
34 => new Facility(facility, "FACILITY_STATE_MANAGEMENT"),
35 => new Facility(facility, "FACILITY_METADIRECTORY"),
36 => new Facility(facility, "FACILITY_WINDOWSUPDATE"),
37 => new Facility(facility, "FACILITY_DIRECTORYSERVICE"),
39 => new Facility(facility, "FACILITY_SHELL"),
51 => new Facility(facility, "FACILITY_WINRM"),
53 => new Facility(facility, "FACILITY_USERMODE_HYPERVISOR"),
54 => new Facility(facility, "FACILITY_CMI"),
55 => new Facility(facility, "FACILITY_USERMODE_VIRTUALIZATION"),
56 => new Facility(facility, "FACILITY_USERMODE_VOLMGR"),
57 => new Facility(facility, "FACILITY_BCD"),
58 => new Facility(facility, "FACILITY_USERMODE_VHD"),
60 => new Facility(facility, "FACILITY_SDIAG"),
61 => new Facility(facility, "FACILITY_WEBSERVICES"),
80 => new Facility(facility, "FACILITY_WINDOWS_DEFENDER"),
81 => new Facility(facility, "FACILITY_OPC"),
_ => new Facility(facility, $"{facility}", isMatch: false),
};
}
}
}

0 comments on commit 723d45c

Please sign in to comment.