From b63837e4660e04aa6baabe1a96c3391f48402280 Mon Sep 17 00:00:00 2001 From: apmoskevitz Date: Mon, 23 Sep 2024 18:53:15 -0400 Subject: [PATCH] fixed conversions tests failing by adding a polyfill for the frameworks that do not have the nullability attributes --- .../Util/CSharpPrimitiveCast.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs b/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs index 015251fe9..f39ee4404 100644 --- a/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs +++ b/ICSharpCode.Decompiler/Util/CSharpPrimitiveCast.cs @@ -35,8 +35,10 @@ namespace ICSharpCode.Decompiler.Util /// /// Overflow checking is enabled and an overflow occurred. /// The cast is invalid, e.g. casting a boolean to an integer. - //[return: MaybeNull] - //[return: NotNullIfNotNull(nameof(input))] + /// + + [return: MaybeNull] + [return: NotNullIfNotNull("input")] public static object Cast(TypeCode targetType, [MaybeNull] object input, bool checkForOverflow) { if (input == null) @@ -772,3 +774,35 @@ namespace ICSharpCode.Decompiler.Util } } } +#if (!NETSTANDARD2_0_OR_GREATER && !NETCORE) || MCS +namespace System.Diagnostics.CodeAnalysis +{ + /// Specifies that the output will be non-null if the named parameter is non-null. + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] + internal sealed class NotNullIfNotNullAttribute : Attribute + { + /// Initializes the attribute with the associated parameter name. + /// + /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. + /// + public NotNullIfNotNullAttribute(string parameterName) + { + ParameterName = parameterName; + } + private string _parameterName; + /// Gets the associated parameter name. + public string ParameterName { + get { + return _parameterName; + } + private set { + _parameterName = value; + } + } + } + + /// Specifies that an output may be null even if the corresponding type disallows it. + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, Inherited = false)] + internal sealed class MaybeNullAttribute : Attribute { } +} +#endif \ No newline at end of file