diff --git a/src/fsharp/FSharp.Core/Nullable.fs b/src/fsharp/FSharp.Core/Nullable.fs index eb278c1fd63..02d58b2a8ac 100644 --- a/src/fsharp/FSharp.Core/Nullable.fs +++ b/src/fsharp/FSharp.Core/Nullable.fs @@ -99,6 +99,9 @@ module Nullable = [] let inline int (value:Nullable<_>) = if value.HasValue then Nullable(Operators.int value.Value) else Nullable() + [] + let inline uint (value: Nullable<_>) = if value.HasValue then Nullable(Operators.uint value.Value) else Nullable() + [] let inline enum (value:Nullable< int32 >) = if value.HasValue then Nullable(Operators.enum value.Value) else Nullable() diff --git a/src/fsharp/FSharp.Core/Nullable.fsi b/src/fsharp/FSharp.Core/Nullable.fsi index 07313fa458c..777aecdc7ab 100644 --- a/src/fsharp/FSharp.Core/Nullable.fsi +++ b/src/fsharp/FSharp.Core/Nullable.fsi @@ -169,6 +169,14 @@ module Nullable = [] val inline int : value:Nullable< ^T > -> Nullable when ^T : (static member op_Explicit : ^T -> int) and default ^T : int + /// Converts the argument to an unsigned 32-bit integer. This is a direct conversion for all + /// primitive numeric types. The operation requires an appropriate + /// static conversion method on the input type. + /// The input value. + /// The converted unsigned integer + [] + val inline uint: value: Nullable< ^T > -> Nullable when ^T :(static member op_Explicit: ^T -> uint) and default ^T : uint + /// Converts the argument to a particular enum type. /// The input value. /// The converted enum type. diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Linq/NullableOperators.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Linq/NullableOperators.fs new file mode 100644 index 00000000000..1f992316a66 --- /dev/null +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Linq/NullableOperators.fs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Core.UnitTests.FSharp_Core.Linq.NullableOperators + +open NUnit.Framework +open Microsoft.FSharp.Linq + +[] +type NullableOperators() = + [] + member _.CastingUint () = + let expected = Nullable(12u) + let actual = Nullable.uint (Nullable(12)) + Assert.AreEqual(expected, actual) \ No newline at end of file diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs index 896e7629da0..e496f677f6c 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs @@ -2342,6 +2342,7 @@ Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.Single] ToFloat32 Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.Single] ToSingle[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt16] ToUInt16[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt32] ToUInt32[T](System.Nullable`1[T]) +Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt32] ToUInt[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt64] ToUInt64[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UIntPtr] ToUIntPtr[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[TResult] ToEnum[TResult](System.Nullable`1[System.Int32]) diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs index 82141617d93..e2bc4a25a85 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs @@ -2342,6 +2342,7 @@ Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.Single] ToFloat32 Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.Single] ToSingle[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt16] ToUInt16[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt32] ToUInt32[T](System.Nullable`1[T]) +Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt32] ToUInt[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UInt64] ToUInt64[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[System.UIntPtr] ToUIntPtr[T](System.Nullable`1[T]) Microsoft.FSharp.Linq.NullableModule: System.Nullable`1[TResult] ToEnum[TResult](System.Nullable`1[System.Int32])