Closed as not planned
Description
Description
Please improve compiler the methods in System.Type
where a throwOnError
is applicable by specifying code-analysis.
We're not expecting null if throwOnError
is true
.
Proposal
namespace System
public abstract partial class Type : MemberInfo, IReflect
{
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromCLSID(Guid clsid, bool throwOnError) =>
GetTypeFromCLSID(clsid, null, throwOnError: throwOnError);
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromCLSID(Guid clsid, string? server, bool throwOnError) =>
Marshal.GetTypeFromCLSID(clsid, server, throwOnError);
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, bool throwOnError) =>
GetTypeFromProgID(progID, null, throwOnError: throwOnError);
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, string? server, bool throwOnError) =>
Marshal.GetTypeFromProgID(progID, server, throwOnError);
}
The above should be changed to:
public abstract partial class Type : MemberInfo, IReflect
{
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromCLSID(Guid clsid, [NotNullWhen(true)] bool throwOnError) =>
GetTypeFromCLSID(clsid, null, throwOnError: throwOnError);
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromCLSID(Guid clsid, string? server, [NotNullWhen(true)] bool throwOnError) =>
Marshal.GetTypeFromCLSID(clsid, server, throwOnError);
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, [NotNullWhen(true)] bool throwOnError) =>
GetTypeFromProgID(progID, null, throwOnError: throwOnError);
[SupportedOSPlatform("windows")]
public static Type? GetTypeFromProgID(string progID, string? server, [NotNullWhen(true)] bool throwOnError) =>
Marshal.GetTypeFromProgID(progID, server, throwOnError);
}
Feel free to assign me if approved.