Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
Add nullable uint conversion function (dotnet#8780)
Browse files Browse the repository at this point in the history
* Move nullable into separate files (dotnet#8801)

* Move nullable into separate files

* up

* jojo

* bagheera

* caramel

* bagheera2

* derp
  • Loading branch information
cartermp authored and nosami committed Feb 22, 2021
1 parent a6b0745 commit f24c829
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/fsharp/FSharp.Core/Nullable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ module Nullable =
[<CompiledName("ToInt")>]
let inline int (value:Nullable<_>) = if value.HasValue then Nullable(Operators.int value.Value) else Nullable()

[<CompiledName("ToUInt")>]
let inline uint (value: Nullable<_>) = if value.HasValue then Nullable(Operators.uint value.Value) else Nullable()

[<CompiledName("ToEnum")>]
let inline enum (value:Nullable< int32 >) = if value.HasValue then Nullable(Operators.enum value.Value) else Nullable()

Expand Down
8 changes: 8 additions & 0 deletions src/fsharp/FSharp.Core/Nullable.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ module Nullable =
[<CompiledName("ToInt")>]
val inline int : value:Nullable< ^T > -> Nullable<int> when ^T : (static member op_Explicit : ^T -> int) and default ^T : int

/// <summary>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.</summary>
/// <param name="value">The input value.</param>
/// <returns>The converted unsigned integer</returns>
[<CompiledName("ToUInt")>]
val inline uint: value: Nullable< ^T > -> Nullable<uint> when ^T :(static member op_Explicit: ^T -> uint) and default ^T : uint

/// <summary>Converts the argument to a particular enum type.</summary>
/// <param name="value">The input value.</param>
/// <returns>The converted enum type.</returns>
Expand Down
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
type NullableOperators() =
[<Test>]
member _.CastingUint () =
let expected = Nullable(12u)
let actual = Nullable.uint (Nullable(12))
Assert.AreEqual(expected, actual)
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,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])
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,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])
Expand Down

0 comments on commit f24c829

Please sign in to comment.