mirror of https://github.com/dahall/Vanara.git
Code cleanup and further nullability fixes
parent
540367b444
commit
34fd355ed2
|
@ -3034,7 +3034,7 @@ public static partial class Mpr
|
|||
/// <para>The string can be MAX_PATH characters in length, and it must follow the network provider's naming conventions.</para>
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.LPTStr, SizeConst = 260)]
|
||||
public string? lpRemoteName;
|
||||
public string lpRemoteName;
|
||||
|
||||
/// <summary>A pointer to a NULL-terminated string that contains a comment supplied by the network provider.</summary>
|
||||
[MarshalAs(UnmanagedType.LPTStr, SizeConst = 1024)]
|
||||
|
@ -3051,7 +3051,7 @@ public static partial class Mpr
|
|||
public static readonly NETRESOURCE Root = new();
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="NETRESOURCE"/> class.</summary>
|
||||
public NETRESOURCE() { }
|
||||
public NETRESOURCE() => lpRemoteName = string.Empty;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="NETRESOURCE"/> class.</summary>
|
||||
/// <param name="remoteName">
|
||||
|
|
|
@ -2636,7 +2636,7 @@ public static partial class NetApi32
|
|||
public static IEnumerable<T> NetServerEnum<T>(NetServerEnumFilter netServerEnumFilter = NetServerEnumFilter.SV_TYPE_WORKSTATION | NetServerEnumFilter.SV_TYPE_SERVER, string? domain = null, int level = 0) where T : struct, INetServerInfo
|
||||
{
|
||||
if (level == 0) level = GetLevelFromStructure<T>();
|
||||
if (level != 100 && level != 101)
|
||||
if (level is not 100 and not 101)
|
||||
throw new ArgumentOutOfRangeException(nameof(level), @"Only SERVER_INFO_100 or SERVER_INFO_101 are supported as valid structures.");
|
||||
var resumeHandle = IntPtr.Zero;
|
||||
NetServerEnum(null, (uint)level, out var bufptr, MAX_PREFERRED_LENGTH, out var entriesRead, out _, netServerEnumFilter, domain, resumeHandle).ThrowIfFailed();
|
||||
|
@ -2659,7 +2659,7 @@ public static partial class NetApi32
|
|||
public static T NetServerGetInfo<T>([Optional] string? serverName, int level = 0) where T : struct, INetServerInfo
|
||||
{
|
||||
if (level == 0) level = GetLevelFromStructure<T>();
|
||||
if (level != 100 && level != 101 && level != 102)
|
||||
if (level is not 100 and not 101 and not 102)
|
||||
throw new ArgumentOutOfRangeException(nameof(level), @"Only SERVER_INFO_100, SERVER_INFO_101, or SERVER_INFO_102 are supported as valid structures.");
|
||||
NetServerGetInfo(serverName, level, out var ptr).ThrowIfFailed();
|
||||
return ptr.DangerousGetHandle().ToStructure<T>();
|
||||
|
|
|
@ -1733,7 +1733,7 @@ public static partial class PowrProf
|
|||
// PossibleSettingIndex, PUCHAR Buffer, LPDWORD BufferSize );
|
||||
[DllImport(Lib.PowrProf, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
[PInvokeData("powrprof.h", MSDNShortId = "e803dc6b-706a-49fc-8c8d-ba9b0ccf8491")]
|
||||
public static extern Win32Error PowerReadPossibleDescription([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, uint PossibleSettingIndex, StringBuilder Buffer, ref uint BufferSize);
|
||||
public static extern Win32Error PowerReadPossibleDescription([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, uint PossibleSettingIndex, StringBuilder? Buffer, ref uint BufferSize);
|
||||
|
||||
/// <summary>Retrieves the friendly name for one of the possible choices of a power setting value.</summary>
|
||||
/// <param name="RootPowerKey">This parameter is reserved for future use and must be set to <c>NULL</c>.</param>
|
||||
|
@ -1806,7 +1806,7 @@ public static partial class PowrProf
|
|||
// PossibleSettingIndex, PUCHAR Buffer, LPDWORD BufferSize );
|
||||
[DllImport(Lib.PowrProf, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
[PInvokeData("powrprof.h", MSDNShortId = "38f3c5f4-ec65-47f0-b15c-36cd2b1e2813")]
|
||||
public static extern Win32Error PowerReadPossibleFriendlyName([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, uint PossibleSettingIndex, StringBuilder Buffer, ref uint BufferSize);
|
||||
public static extern Win32Error PowerReadPossibleFriendlyName([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, uint PossibleSettingIndex, StringBuilder? Buffer, ref uint BufferSize);
|
||||
|
||||
/// <summary>Retrieves the value for a possible value of a power setting.</summary>
|
||||
/// <param name="RootPowerKey">This parameter is reserved for future use and must be set to <c>NULL</c>.</param>
|
||||
|
@ -2200,7 +2200,7 @@ public static partial class PowrProf
|
|||
// *Buffer, LPDWORD BufferSize );
|
||||
[DllImport(Lib.PowrProf, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
[PInvokeData("powrprof.h", MSDNShortId = "48ad80b7-f89a-4dad-a991-056ce41d6975")]
|
||||
public static extern Win32Error PowerReadValueUnitsSpecifier([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, StringBuilder Buffer, ref uint BufferSize);
|
||||
public static extern Win32Error PowerReadValueUnitsSpecifier([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, StringBuilder? Buffer, ref uint BufferSize);
|
||||
|
||||
/// <summary>Deletes the specified power setting.</summary>
|
||||
/// <param name="PowerSettingSubKeyGuid">
|
||||
|
@ -3366,7 +3366,7 @@ public static partial class PowrProf
|
|||
// *Buffer, DWORD BufferSize );
|
||||
[DllImport(Lib.PowrProf, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)]
|
||||
[PInvokeData("powrprof.h", MSDNShortId = "d9a81077-23e8-4bae-8e70-ffaaaf1ecda3")]
|
||||
public static extern Win32Error PowerWriteValueUnitsSpecifier([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, string Buffer, uint BufferSize);
|
||||
public static extern Win32Error PowerWriteValueUnitsSpecifier([Optional] HKEY RootPowerKey, in Guid SubGroupOfPowerSettingsGuid, in Guid PowerSettingGuid, string? Buffer, uint BufferSize);
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using static Vanara.PInvoke.Kernel32;
|
||||
|
||||
|
@ -1386,7 +1387,7 @@ public static partial class AdvApi32
|
|||
[PInvokeData("winbase.h", MSDNShortId = "dcfdcd5b-0269-4081-b1db-e272171c27a2")]
|
||||
public static bool CreateProcessWithLogonW(string lpUsername, [Optional] string? lpDomain, string lpPassword, ProcessLogonFlags dwLogonFlags,
|
||||
[Optional] string? lpApplicationName, [Optional] StringBuilder? lpCommandLine, CREATE_PROCESS dwCreationFlags,
|
||||
[Optional] string[]? lpEnvironment, [Optional] string? lpCurrentDirectory, in STARTUPINFO lpStartupInfo, out SafePROCESS_INFORMATION? lpProcessInformation)
|
||||
[Optional] string[]? lpEnvironment, [Optional] string? lpCurrentDirectory, in STARTUPINFO lpStartupInfo, [NotNullWhen(true)] out SafePROCESS_INFORMATION? lpProcessInformation)
|
||||
{
|
||||
var ret = CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, out PROCESS_INFORMATION pi);
|
||||
lpProcessInformation = ret ? new SafePROCESS_INFORMATION(pi) : null;
|
||||
|
|
|
@ -3201,6 +3201,10 @@ public static partial class SetupAPI
|
|||
Value = mem.ToStringEnum(CharSet.Unicode).ToArray();
|
||||
break;
|
||||
|
||||
case DEVPROPTYPE.DEVPROP_TYPE_BOOLEAN:
|
||||
Value = mem.ToStructure<byte>() != 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
(DEVPROPTYPE type, DEVPROPTYPE mod) spt = propType.Split();
|
||||
var type = convType ?? CorrespondingTypeAttribute.GetCorrespondingTypes(spt.type).FirstOrDefault();
|
||||
|
|
|
@ -1427,15 +1427,15 @@ public static partial class SetupAPI
|
|||
public enum SPDRP
|
||||
{
|
||||
/// <summary>The function retrieves the device's address.</summary>
|
||||
[CorrespondingType(typeof(uint))]
|
||||
[CorrespondingType(typeof(uint), CorrespondingAction.Get)]
|
||||
SPDRP_ADDRESS = 0x0000001C,
|
||||
|
||||
/// <summary>The function retrieves the device's bus number.</summary>
|
||||
[CorrespondingType(typeof(uint))]
|
||||
[CorrespondingType(typeof(uint), CorrespondingAction.Get)]
|
||||
SPDRP_BUSNUMBER = 0x00000015,
|
||||
|
||||
/// <summary>The function retrieves the GUID for the device's bus type.</summary>
|
||||
[CorrespondingType(typeof(Guid))]
|
||||
[CorrespondingType(typeof(Guid), CorrespondingAction.Get)]
|
||||
SPDRP_BUSTYPEGUID = 0x00000013,
|
||||
|
||||
/// <summary>
|
||||
|
@ -1489,7 +1489,7 @@ public static partial class SetupAPI
|
|||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(CM_DEVCAP))]
|
||||
[CorrespondingType(typeof(CM_DEVCAP), CorrespondingAction.Get)]
|
||||
SPDRP_CAPABILITIES = 0x0000000F,
|
||||
|
||||
/// <summary>
|
||||
|
@ -1500,7 +1500,7 @@ public static partial class SetupAPI
|
|||
SPDRP_CHARACTERISTICS = 0x0000001B,
|
||||
|
||||
/// <summary>The function retrieves a REG_SZ string that contains the device setup class of a device.</summary>
|
||||
[CorrespondingType(typeof(string))]
|
||||
[CorrespondingType(typeof(string), CorrespondingAction.Get)]
|
||||
SPDRP_CLASS = 0x00000007,
|
||||
|
||||
/// <summary>The function retrieves a REG_SZ string that contains the GUID that represents the device setup class of a device.</summary>
|
||||
|
@ -1525,7 +1525,7 @@ public static partial class SetupAPI
|
|||
/// <summary>
|
||||
/// (Windows XP and later) The function retrieves a CM_POWER_DATA structure that contains the device's power management information.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(CM_POWER_DATA))]
|
||||
[CorrespondingType(typeof(CM_POWER_DATA), CorrespondingAction.Get)]
|
||||
SPDRP_DEVICE_POWER_DATA = 0x0000001E,
|
||||
|
||||
/// <summary>The function retrieves a REG_SZ string that contains the description of a device.</summary>
|
||||
|
@ -1546,7 +1546,7 @@ public static partial class SetupAPI
|
|||
SPDRP_DRIVER = 0x00000009,
|
||||
|
||||
/// <summary>The function retrieves a REG_SZ string that contains the name of the device's enumerator.</summary>
|
||||
[CorrespondingType(typeof(string))]
|
||||
[CorrespondingType(typeof(string), CorrespondingAction.Get)]
|
||||
SPDRP_ENUMERATOR_NAME = 0x00000016,
|
||||
|
||||
/// <summary>
|
||||
|
@ -1573,11 +1573,11 @@ public static partial class SetupAPI
|
|||
/// installation state is represented by one of the CM_INSTALL_STATE_Xxx values that are defined in Cfgmgr32.h. The
|
||||
/// CM_INSTALL_STATE_Xxx values correspond to the DEVICE_INSTALL_STATE enumeration values.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(CM_INSTALL_STATE))]
|
||||
[CorrespondingType(typeof(CM_INSTALL_STATE), CorrespondingAction.Get)]
|
||||
SPDRP_INSTALL_STATE = 0x00000022,
|
||||
|
||||
/// <summary>The function retrieves the device's legacy bus type as an INTERFACE_TYPE value (defined in Wdm.h and Ntddk.h).</summary>
|
||||
[CorrespondingType(typeof(INTERFACE_TYPE))]
|
||||
[CorrespondingType(typeof(INTERFACE_TYPE), CorrespondingAction.Get)]
|
||||
SPDRP_LEGACYBUSTYPE = 0x00000014,
|
||||
|
||||
/// <summary>The function retrieves a REG_SZ string that contains the hardware location of a device.</summary>
|
||||
|
@ -1588,8 +1588,8 @@ public static partial class SetupAPI
|
|||
/// (Windows Server 2003 and later) The function retrieves a REG_MULTI_SZ string that represents the location of the device in
|
||||
/// the device tree.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(System.Collections.Generic.IEnumerable<string>))]
|
||||
[CorrespondingType(typeof(string[]))]
|
||||
[CorrespondingType(typeof(System.Collections.Generic.IEnumerable<string>), CorrespondingAction.Get)]
|
||||
[CorrespondingType(typeof(string[]), CorrespondingAction.Get)]
|
||||
SPDRP_LOCATION_PATHS = 0x00000023,
|
||||
|
||||
/// <summary>The function retrieves a REG_MULTI_SZ string that contains the names of a device's lower-filter drivers.</summary>
|
||||
|
@ -1605,21 +1605,21 @@ public static partial class SetupAPI
|
|||
/// The function retrieves a REG_SZ string that contains the name that is associated with the device's PDO. For more
|
||||
/// information, see IoCreateDevice.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(string))]
|
||||
[CorrespondingType(typeof(string), CorrespondingAction.Get)]
|
||||
SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = 0x0000000E,
|
||||
|
||||
/// <summary>
|
||||
/// (Windows XP and later) The function retrieves the device's current removal policy as a DWORD that contains one of the
|
||||
/// CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(CM_REMOVAL_POLICY))]
|
||||
[CorrespondingType(typeof(CM_REMOVAL_POLICY), CorrespondingAction.Get)]
|
||||
SPDRP_REMOVAL_POLICY = 0x0000001F,
|
||||
|
||||
/// <summary>
|
||||
/// (Windows XP and later) The function retrieves the device's hardware-specified default removal policy as a DWORD that
|
||||
/// contains one of the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(CM_REMOVAL_POLICY))]
|
||||
[CorrespondingType(typeof(CM_REMOVAL_POLICY), CorrespondingAction.Get)]
|
||||
SPDRP_REMOVAL_POLICY_HW_DEFAULT = 0x00000020,
|
||||
|
||||
/// <summary>
|
||||
|
@ -1638,7 +1638,7 @@ public static partial class SetupAPI
|
|||
/// descriptor strings, see Security Descriptor Definition Language (Windows). For information about the format of security
|
||||
/// descriptor strings, see Security Descriptor Definition Language (Windows).
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(string))]
|
||||
[CorrespondingType(typeof(string), CorrespondingAction.Set)]
|
||||
SPDRP_SECURITY_SDS = 0x00000018,
|
||||
|
||||
/// <summary>The function retrieves a REG_SZ string that contains the service name for a device.</summary>
|
||||
|
@ -1648,7 +1648,7 @@ public static partial class SetupAPI
|
|||
/// <summary>
|
||||
/// The function retrieves a DWORD value set to the value of the <c>UINumber</c> member of the device's DEVICE_CAPABILITIES structure.
|
||||
/// </summary>
|
||||
[CorrespondingType(typeof(uint))]
|
||||
[CorrespondingType(typeof(uint), CorrespondingAction.Get)]
|
||||
SPDRP_UI_NUMBER = 0x00000010,
|
||||
|
||||
/// <summary>The function retrieves a format string (REG_SZ) used to display the <c>UINumber</c> value.</summary>
|
||||
|
@ -1661,7 +1661,7 @@ public static partial class SetupAPI
|
|||
SPDRP_UPPERFILTERS = 0x00000011,
|
||||
|
||||
/// <summary>Base ContainerID (R)</summary>
|
||||
[CorrespondingType(typeof(Guid))]
|
||||
[CorrespondingType(typeof(Guid), CorrespondingAction.Get)]
|
||||
SPDRP_BASE_CONTAINERID = 0x00000024,
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
public static partial class ShlwApi
|
||||
{
|
||||
/// <summary>CLSID_QueryAssociations</summary>
|
||||
public static readonly Guid CLSID_QueryAssociations = new Guid("a07034fd-6caa-4954-ac3f-97a27216f98a");
|
||||
public static readonly Guid CLSID_QueryAssociations = new("a07034fd-6caa-4954-ac3f-97a27216f98a");
|
||||
|
||||
/// <summary>Provides information to the <c>IQueryAssociations</c> interface methods.</summary>
|
||||
// typedef enum { ASSOCF_NONE = 0x00000000, ASSOCF_INIT_NOREMAPCLSID = 0x00000001, ASSOCF_INIT_BYEXENAME = 0x00000002,
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using Vanara.Extensions;
|
||||
using Vanara.InteropServices;
|
||||
using Vanara.PInvoke;
|
||||
using static Vanara.PInvoke.AdvApi32;
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using static Vanara.PInvoke.Authz;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using Vanara.Extensions;
|
||||
using Vanara.PInvoke;
|
||||
using static Vanara.PInvoke.AdvApi32;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using static Vanara.PInvoke.AdvApi32;
|
||||
using static Vanara.PInvoke.AdvApi32;
|
||||
using Vanara.PInvoke;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
|
||||
namespace Vanara.Extensions;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Security.Principal;
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace Vanara.Security;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using Vanara.Extensions.Reflection;
|
||||
using static Vanara.PInvoke.NTDSApi;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using Vanara.Extensions;
|
||||
using Vanara.PInvoke;
|
||||
using static Vanara.PInvoke.AdvApi32;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Security.Principal;
|
||||
using static Vanara.PInvoke.AdvApi32;
|
||||
|
@ -36,7 +35,7 @@ public class WindowsLoggedInIdentity : IDisposable, IIdentity
|
|||
/// The logon provider. This parameter can usually be left as the default. For more information, lookup more detail for the
|
||||
/// dwLogonProvider parameter of the Windows LogonUser function.
|
||||
/// </param>
|
||||
public WindowsLoggedInIdentity(string userName, string domainName, string password, LogonUserType logonType = LogonUserType.LOGON32_LOGON_INTERACTIVE,
|
||||
public WindowsLoggedInIdentity(string userName, string? domainName, string password, LogonUserType logonType = LogonUserType.LOGON32_LOGON_INTERACTIVE,
|
||||
LogonUserProvider provider = LogonUserProvider.LOGON32_PROVIDER_DEFAULT)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userName)) throw new ArgumentNullException(nameof(userName));
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Principal;
|
||||
|
|
|
@ -74,7 +74,7 @@ public class WinHTTPTests
|
|||
|
||||
Assert.That(WinHttpCreateProxyResolver(hSession, out SafeHINTERNET hResolver), ResultIs.Successful);
|
||||
|
||||
using System.Threading.ManualResetEvent evt = new System.Threading.ManualResetEvent(false);
|
||||
using System.Threading.ManualResetEvent evt = new(false);
|
||||
Win32Error cbErr = Win32Error.ERROR_SUCCESS;
|
||||
IntPtr prevCb = WinHttpSetStatusCallback(hResolver, callback, WINHTTP_CALLBACK_FLAG.WINHTTP_CALLBACK_FLAG_REQUEST_ERROR | WINHTTP_CALLBACK_FLAG.WINHTTP_CALLBACK_FLAG_GETPROXYFORURL_COMPLETE);
|
||||
Assert.That(prevCb, Is.Not.EqualTo(WINHTTP_INVALID_STATUS_CALLBACK));
|
||||
|
|
Loading…
Reference in New Issue