From 1019bed59897c6a400518dede18786f1076a8c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 24 Sep 2025 18:18:01 +0100 Subject: [PATCH] Add IntelliSense comments to `Nullable` classes --- nanoFramework.CoreLibrary/System/Nullable.cs | 64 +++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/nanoFramework.CoreLibrary/System/Nullable.cs b/nanoFramework.CoreLibrary/System/Nullable.cs index 89f1dc5..e7c0609 100644 --- a/nanoFramework.CoreLibrary/System/Nullable.cs +++ b/nanoFramework.CoreLibrary/System/Nullable.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. #pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals +#nullable enable namespace System { @@ -14,26 +15,46 @@ namespace System /// /// Represents a value type that can be assigned . /// - /// + /// The underlying value type of the generic type. [Serializable] public partial struct Nullable where T : struct { // Do not rename (binary serialization) private readonly bool hasValue; // Do not rename (binary serialization) or make readonly (can be mutated in ToString, etc.) - internal T value; + internal T value; + /// + /// Initializes a new instance of the structure to the specified value. + /// + /// A value type. + /// + /// The constructor initializes the HasValue property of the new object to , and the Value property to the value of the parameter. + /// public Nullable(T value) { this.value = value; hasValue = true; } + /// + /// Gets a value indicating whether the current object has a valid value of its underlying type. + /// + /// + /// if the current object has a value; if the current object has no . + /// public readonly bool HasValue { get => hasValue; } + /// + /// Gets the value of the current object if it has been assigned a valid underlying value. + /// + /// + /// The value of the current object if the property is . An exception is thrown if the property is . + /// + /// The property is . public readonly T Value { get @@ -46,11 +67,27 @@ public readonly T Value } } + /// + /// Retrieves the value of the current object, or the default value of the underlying type. + /// + /// The value of the property if the property is ; otherwise, the default value of the underlying type. + /// + /// The method returns a value even if the property is (unlike the property, which throws an exception). If the property is , the method returns the default value of the underlying type. + /// public readonly T GetValueOrDefault() => value; + /// + /// Retrieves the value of the current object, or the specified default value. + /// + /// A value to return if the property is . + /// The value of the property if the property is ; otherwise, the default value of the underlying type. + /// + /// The method returns a value even if the property is (unlike the property, which throws an exception). If the property is , the method returns the default value of the underlying type. + /// public readonly T GetValueOrDefault(T defaultValue) => hasValue ? value : defaultValue; + /// public override bool Equals(object? other) { if (!hasValue) @@ -66,16 +103,31 @@ public override bool Equals(object? other) return value.Equals(other); } + /// public override int GetHashCode() => hasValue ? value.GetHashCode() : 0; + /// public override string? ToString() => hasValue ? value.ToString() : ""; + /// + /// Creates a new object initialized to a specified value. + /// + /// A value type. + /// A object whose property is initialized with the value parameter. public static implicit operator T?(T value) => new T?(value); + /// + /// Defines an explicit conversion of a instance to its underlying value. + /// + /// A nullable value. + /// The value of the property of the parameter. public static explicit operator T(T? value) => value!.Value; } + /// + /// Supports a value type that can be assigned . This class cannot be inherited. + /// public static class Nullable { //public static int Compare(T? n1, T? n2) where T : struct @@ -100,6 +152,12 @@ public static class Nullable // return true; //} + /// + /// Returns the underlying type argument of the specified nullable type. + /// + /// A object that describes a closed generic nullable type. + /// The type argument of the parameter, if the parameter is a closed generic nullable type; otherwise, . + /// is . // If the type provided is not a Nullable Type, return null. // Otherwise, return the underlying type of the Nullable type public static Type? GetUnderlyingType(Type nullableType) @@ -110,6 +168,7 @@ public static class Nullable { // Instantiated generic type only Type genericType = nullableType.GetGenericTypeDefinition(); + if (ReferenceEquals(genericType, typeof(Nullable<>))) { return nullableType.GetGenericArguments()[0]; @@ -127,6 +186,7 @@ public static class Nullable /// /// As the returned readonly reference refers to data that is stored in the input value, this method should only ever be /// called when the input reference points to a value with an actual location and not an "rvalue" (an expression that may appear on the right side but not left side of an assignment). That is, if this API is called and the input reference + /// called when the input reference points to a value with an actual location and not an "rvalue" (an expression that may appear on the right side but not left side of an assignment). That is, if this API is called and the input reference /// points to a value that is produced by the compiler as a defensive copy or a temporary copy, the behavior might not match the desired one. /// public static ref readonly T GetValueRefOrDefaultRef(ref readonly T? nullable)