Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullable uint conversion function #8780

Merged
merged 3 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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])
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 @@ -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])
Expand Down