Partial nullability for FwpUCInt

nullableenabled
David Hall 2023-09-14 19:48:29 -06:00
parent de3e905ee1
commit 041879efba
5 changed files with 33 additions and 17 deletions

View File

@ -2855,7 +2855,7 @@ public static partial class FwpUClnt
private readonly IntPtr _localPrincipalGroupSids;
/// <summary>Groups in the local security principal's token.</summary>
public string[] localPrincipalGroupSids => _localPrincipalGroupSids.ToStringEnum((int)numLocalPrincipalGroupSids, CharSet.Unicode).ToArray();
public string[] localPrincipalGroupSids => _localPrincipalGroupSids.ToStringEnum((int)numLocalPrincipalGroupSids, CharSet.Unicode).WhereNotNull().ToArray();
/// <summary>Number of groups in the remote security principal's token.</summary>
public uint numRemotePrincipalGroupSids;
@ -2863,7 +2863,7 @@ public static partial class FwpUClnt
private readonly IntPtr _remotePrincipalGroupSids;
/// <summary>Groups in the remote security principal's token.</summary>
public string[] remotePrincipalGroupSids => _remotePrincipalGroupSids.ToStringEnum((int)numRemotePrincipalGroupSids, CharSet.Unicode).ToArray();
public string[] remotePrincipalGroupSids => _remotePrincipalGroupSids.ToStringEnum((int)numRemotePrincipalGroupSids, CharSet.Unicode).WhereNotNull().ToArray();
/// <summary>Type of traffic for which the embedded quick mode was being negotiated.</summary>
public IPSEC_TRAFFIC_TYPE saTrafficType;
@ -3013,7 +3013,7 @@ public static partial class FwpUClnt
private readonly IntPtr _localPrincipalGroupSids;
/// <summary>Groups in the local security principal's token.</summary>
public string[] localPrincipalGroupSids => _localPrincipalGroupSids.ToStringEnum((int)numLocalPrincipalGroupSids, CharSet.Unicode).ToArray();
public string[] localPrincipalGroupSids => _localPrincipalGroupSids.ToStringEnum((int)numLocalPrincipalGroupSids, CharSet.Unicode).WhereNotNull().ToArray();
/// <summary>Number of groups in the remote security principal's token.</summary>
public uint numRemotePrincipalGroupSids;
@ -3021,7 +3021,7 @@ public static partial class FwpUClnt
private readonly IntPtr _remotePrincipalGroupSids;
/// <summary>Groups in the remote security principal's token.</summary>
public string[] remotePrincipalGroupSids => _remotePrincipalGroupSids.ToStringEnum((int)numRemotePrincipalGroupSids, CharSet.Unicode).ToArray();
public string[] remotePrincipalGroupSids => _remotePrincipalGroupSids.ToStringEnum((int)numRemotePrincipalGroupSids, CharSet.Unicode).WhereNotNull().ToArray();
}
/// <summary>
@ -4110,7 +4110,7 @@ public static partial class FwpUClnt
/// <summary>Optional name of the Windows service hosting the provider. This allows BFE to detect that a provider has been disabled.</summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string serviceName;
public string? serviceName;
}
/// <summary>The <c>FWPM_SESSION_ENUM_TEMPLATE0</c> structure is used for enumerating sessions.</summary>
@ -4540,7 +4540,7 @@ public static partial class FwpUClnt
public IntPtr ports;
/// <summary>Array of IP port numbers ( <see cref="ushort"/>) for the specified type.</summary>
public ushort[] GetPorts() => ports.ToArray<ushort>((int)numPorts);
public ushort[] GetPorts() => ports.ToArray<ushort>((int)numPorts) ?? new ushort[0];
}
/// <summary>The <c>FWPM_SYSTEM_PORTS0</c> structure contains information about all of the system ports of all types.</summary>
@ -4561,7 +4561,7 @@ public static partial class FwpUClnt
public IntPtr types;
/// <summary>A <see cref="FWPM_SYSTEM_PORTS_BY_TYPE0"/> structure that specifies the array of system port types.</summary>
public FWPM_SYSTEM_PORTS_BY_TYPE0[] GetTypes() => types.ToArray<FWPM_SYSTEM_PORTS_BY_TYPE0>((int)numTypes);
public FWPM_SYSTEM_PORTS_BY_TYPE0[] GetTypes() => types.ToArray<FWPM_SYSTEM_PORTS_BY_TYPE0>((int)numTypes) ?? new FWPM_SYSTEM_PORTS_BY_TYPE0[0];
}
/// <summary>
@ -4637,7 +4637,7 @@ public static partial class FwpUClnt
public static implicit operator POSITIONINFO(_POSITIONINFO i) => new()
{
numvSwitchFilterExtensions = i.numvSwitchFilterExtensions,
vSwitchFilterExtensions = i.vSwitchFilterExtensions.ToStringEnum((int)i.numvSwitchFilterExtensions, CharSet.Unicode).ToArray()
vSwitchFilterExtensions = i.vSwitchFilterExtensions.ToStringEnum((int)i.numvSwitchFilterExtensions, CharSet.Unicode).WhereNotNull().ToArray()
};
}
@ -4659,7 +4659,7 @@ public static partial class FwpUClnt
{
inRequiredPosition = i.inRequiredPosition,
numvSwitchFilterExtensions = i.numvSwitchFilterExtensions,
vSwitchFilterExtensions = i.vSwitchFilterExtensions.ToStringEnum((int)i.numvSwitchFilterExtensions, CharSet.Unicode).ToArray()
vSwitchFilterExtensions = i.vSwitchFilterExtensions.ToStringEnum((int)i.numvSwitchFilterExtensions, CharSet.Unicode).WhereNotNull().ToArray()
};
}

View File

@ -983,6 +983,6 @@ public static partial class FwpUClnt
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="item">The value.</param>
/// <returns>The name of the property or <see langword="null"/> if not found.</returns>
public static string GetNameOf<T>(T item) => typeof(FwpUClnt).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).
public static string? GetNameOf<T>(T item) => typeof(FwpUClnt).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).
Where(pi => pi.PropertyType == typeof(T) && Equals(pi.GetValue(null), item)).Select(pi => pi.Name).FirstOrDefault();
}

View File

@ -647,7 +647,7 @@ public static partial class FwpUClnt
// PSECURITY_DESCRIPTOR *securityDescriptor );
[DllImport(Lib_Fwpuclnt, SetLastError = false, ExactSpelling = true)]
[PInvokeData("fwpmu.h", MSDNShortId = "NF:fwpmu.FwpmCalloutGetSecurityInfoByKey0")]
public static extern Win32Error FwpmCalloutGetSecurityInfoByKey0([In] HFWPENG engineHandle, in Guid key, [In] SECURITY_INFORMATION securityInfo,
public static extern Win32Error FwpmCalloutGetSecurityInfoByKey0([In] HFWPENG engineHandle, [Optional] in Guid key, [In] SECURITY_INFORMATION securityInfo,
out PSID sidOwner, out PSID sidGroup, out PACL dacl, out PACL sacl, out SafeFwpmMem securityDescriptor);
/// <summary>
@ -733,7 +733,7 @@ public static partial class FwpUClnt
// [in, optional] const SID *sidOwner, [in, optional] const SID *sidGroup, [in, optional] const ACL *dacl, [in, optional] const ACL *sacl );
[DllImport(Lib_Fwpuclnt, SetLastError = false, ExactSpelling = true)]
[PInvokeData("fwpmu.h", MSDNShortId = "NF:fwpmu.FwpmCalloutSetSecurityInfoByKey0")]
public static extern Win32Error FwpmCalloutSetSecurityInfoByKey0([In] HFWPENG engineHandle, in Guid key, [In] SECURITY_INFORMATION securityInfo,
public static extern Win32Error FwpmCalloutSetSecurityInfoByKey0([In] HFWPENG engineHandle, [Optional] in Guid key, [In] SECURITY_INFORMATION securityInfo,
[In, Optional] PSID sidOwner, [In, Optional] PSID sidGroup, [In, Optional] PACL dacl, [In, Optional] PACL sacl);
/// <summary>
@ -1674,7 +1674,15 @@ public static partial class FwpUClnt
/// <para>Examples</para>
/// <para>The following C++ example uses <c>FwpmEngineOpen0</c> to open a filter session.</para>
/// <para>
/// <code>// Open a session to the filter engine HFWPENG engineHandle = NULL; DWORD result = ERROR_SUCCESS; printf("Opening the filter engine.\n"); result = FwpmEngineOpen0( NULL, RPC_C_AUTHN_WINNT, NULL, NULL, &amp;engineHandle ); if (result != ERROR_SUCCESS) printf("FwpmEngineOpen0 failed. Return value: %d.\n", result); else printf("Filter engine opened successfully.\n");</code>
/// <code language="cpp"><![CDATA[// Open a session to the filter engine
/// HFWPENG engineHandle = NULL;
/// DWORD result = ERROR_SUCCESS;
/// printf("Opening the filter engine.\n");
/// result = FwpmEngineOpen0( NULL, RPC_C_AUTHN_WINNT, NULL, NULL, &amp;engineHandle );
/// if (result != ERROR_SUCCESS)
/// printf("FwpmEngineOpen0 failed. Return value: %d.\n", result);
/// else
/// printf("Filter engine opened successfully.\n");]]></code>
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nf-fwpmu-fwpmengineopen0 DWORD FwpmEngineOpen0( [in, optional] const wchar_t
@ -1755,7 +1763,15 @@ public static partial class FwpUClnt
/// <para>Examples</para>
/// <para>The following C++ example uses <c>FwpmEngineOpen0</c> to open a filter session.</para>
/// <para>
/// <code>// Open a session to the filter engine HFWPENG engineHandle = NULL; DWORD result = ERROR_SUCCESS; printf("Opening the filter engine.\n"); result = FwpmEngineOpen0( NULL, RPC_C_AUTHN_WINNT, NULL, NULL, &amp;engineHandle ); if (result != ERROR_SUCCESS) printf("FwpmEngineOpen0 failed. Return value: %d.\n", result); else printf("Filter engine opened successfully.\n");</code>
/// <code language="cpp"><![CDATA[// Open a session to the filter engine
/// HFWPENG engineHandle = NULL;
/// DWORD result = ERROR_SUCCESS;
/// printf("Opening the filter engine.\n");
/// result = FwpmEngineOpen0( NULL, RPC_C_AUTHN_WINNT, NULL, NULL, &amp;engineHandle );
/// if (result != ERROR_SUCCESS)
/// printf("FwpmEngineOpen0 failed. Return value: %d.\n", result);
/// else
/// printf("Filter engine opened successfully.\n");]]></code>
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nf-fwpmu-fwpmengineopen0 DWORD FwpmEngineOpen0( [in, optional] const wchar_t

View File

@ -1446,7 +1446,7 @@ public static partial class FwpUClnt
// [in, optional] const SID *sidOwner, [in, optional] const SID *sidGroup, [in, optional] const ACL *dacl, [in, optional] const ACL *sacl );
[DllImport(Lib_Fwpuclnt, SetLastError = false, ExactSpelling = true)]
[PInvokeData("fwpmu.h", MSDNShortId = "NF:fwpmu.FwpmFilterSetSecurityInfoByKey0")]
public static extern Win32Error FwpmFilterSetSecurityInfoByKey0([In] HFWPENG engineHandle, in Guid key, SECURITY_INFORMATION securityInfo,
public static extern Win32Error FwpmFilterSetSecurityInfoByKey0([In] HFWPENG engineHandle, [Optional] in Guid key, SECURITY_INFORMATION securityInfo,
[In, Optional] PSID sidOwner, [In, Optional] PSID sidGroup, [In, Optional] PACL dacl, [In, Optional] PACL sacl);
/// <summary>
@ -1712,7 +1712,7 @@ public static partial class FwpUClnt
// https://docs.microsoft.com/en-us/windows/win32/api/fwpmu/nf-fwpmu-fwpmgetappidfromfilename0 DWORD FwpmGetAppIdFromFileName0( [in]
// PCWSTR fileName, [out] FWP_BYTE_BLOB **appId );
[PInvokeData("fwpmu.h", MSDNShortId = "NF:fwpmu.FwpmGetAppIdFromFileName0")]
public static Win32Error FwpmGetAppIdFromFileName0([MarshalAs(UnmanagedType.LPWStr)] string fileName, out byte[] appId)
public static Win32Error FwpmGetAppIdFromFileName0([MarshalAs(UnmanagedType.LPWStr)] string fileName, out byte[]? appId)
{
Win32Error err = FwpmGetAppIdFromFileName0(fileName, out SafeFwpmMem mem);
FWP_BYTE_BLOB blob = mem.ToStructure<FWP_BYTE_BLOB>().GetValueOrDefault();

View File

@ -1298,7 +1298,7 @@ public static partial class FwpUClnt
/// of elements.
/// </param>
/// <returns>An array of type <typeparamref name="T"/> of length <paramref name="elemCount"/>.</returns>
public T[] ToArray<T>(SizeT elemCount, bool byRef) => byRef ? Array.ConvertAll(handle.ToArray<IntPtr>(elemCount) ?? new IntPtr[0], p => p.Convert<T>(uint.MaxValue, CharSet.Unicode)) : handle.ToArray<T>(elemCount) ?? new T[0];
public T[] ToArray<T>(SizeT elemCount, bool byRef) => byRef ? Array.ConvertAll(handle.ToArray<IntPtr>(elemCount) ?? new IntPtr[0], p => p.Convert<T>(uint.MaxValue, CharSet.Unicode)!) : handle.ToArray<T>(elemCount) ?? new T[0];
/// <summary>Extracts a structure from this memory.</summary>
/// <typeparam name="T">The type of the structure to extract.</typeparam>