Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit34d720b

Browse files
committed
add Checked.int8/uint8 and Nullable.int8/uint8
1 parentca40a40 commit34d720b

File tree

5 files changed

+95
-6
lines changed

5 files changed

+95
-6
lines changed

‎src/fsharp/FSharp.Core/Linq.fs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ module NullableOperators =
7777
moduleNullable=
7878

7979
openSystem
80+
81+
[<CompiledName("ToUInt8")>]
82+
letinlineuint8(x:Nullable< ^T>)=ifx.HasValuethenNullable(byte x.Value)elseNullable()
83+
84+
[<CompiledName("ToInt8")>]
85+
letinlineint8(x:Nullable< ^T>)=ifx.HasValuethenNullable(sbyte x.Value)elseNullable()
86+
8087
[<CompiledName("ToByte")>]
8188
letinlinebyte(x:Nullable< ^T>)=ifx.HasValuethenNullable(byte x.Value)elseNullable()
8289

@@ -307,11 +314,13 @@ module LeafExpressionConverter =
307314
let(|ConvFloatQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> float x))
308315
let(|ConvFloat32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> float32 x))
309316
let(|ConvSByteQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> sbyte x))
317+
let(|ConvInt8Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> sbyte x))
310318
let(|ConvInt16Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> int16 x))
311319
let(|ConvInt32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> int32 x))
312320
let(|ConvIntQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> int x))
313321
let(|ConvInt64Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> int64 x))
314322
let(|ConvByteQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> byte x))
323+
let(|ConvUInt8Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> byte x))
315324
let(|ConvUInt16Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> uint16 x))
316325
let(|ConvUInt32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> uint32 x))
317326
let(|ConvUInt64Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> uint64 x))
@@ -321,11 +330,13 @@ module LeafExpressionConverter =
321330
let(|ConvNullableFloatQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.float x))
322331
let(|ConvNullableFloat32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.float32 x))
323332
let(|ConvNullableSByteQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.sbyte x))
333+
let(|ConvNullableInt8Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.int8 x))
324334
let(|ConvNullableInt16Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.int16 x))
325335
let(|ConvNullableInt32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.int32 x))
326336
let(|ConvNullableIntQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.int x))
327337
let(|ConvNullableInt64Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.int64 x))
328338
let(|ConvNullableByteQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.byte x))
339+
let(|ConvNullableUInt8Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.uint8 x))
329340
let(|ConvNullableUInt16Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.uint16 x))
330341
let(|ConvNullableUInt32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.uint32 x))
331342
let(|ConvNullableUInt64Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Nullable.uint64 x))
@@ -338,10 +349,12 @@ module LeafExpressionConverter =
338349
let(|TypeTestGeneric|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> LanguagePrimitives.IntrinsicFunctions.TypeTestGeneric x))
339350
let(|CheckedConvCharQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.char x))
340351
let(|CheckedConvSByteQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.sbyte x))
352+
let(|CheckedConvInt8Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.sbyte x))
341353
let(|CheckedConvInt16Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.int16 x))
342354
let(|CheckedConvInt32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.int32 x))
343355
let(|CheckedConvInt64Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.int64 x))
344356
let(|CheckedConvByteQ|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.byte x))
357+
let(|CheckedConvUInt8Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.byte x))
345358
let(|CheckedConvUInt16Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.uint16 x))
346359
let(|CheckedConvUInt32Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.uint32 x))
347360
let(|CheckedConvUInt64Q|_|)=(|SpecificCallToMethod|_|)(methodhandleof(fun x-> Checked.uint64 x))
@@ -571,11 +584,13 @@ module LeafExpressionConverter =
571584
| ConvNullableFloatQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<float>>)|> asExpr
572585
| ConvNullableFloat32Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<float32>>)|> asExpr
573586
| ConvNullableSByteQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<sbyte>>)|> asExpr
587+
| ConvNullableInt8Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<sbyte>>)|> asExpr
574588
| ConvNullableInt16Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<int16>>)|> asExpr
575589
| ConvNullableInt32Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<int32>>)|> asExpr
576590
| ConvNullableIntQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<int32>>)|> asExpr
577591
| ConvNullableInt64Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<int64>>)|> asExpr
578592
| ConvNullableByteQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<byte>>)|> asExpr
593+
| ConvNullableUInt8Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<byte>>)|> asExpr
579594
| ConvNullableUInt16Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<uint16>>)|> asExpr
580595
| ConvNullableUInt32Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<uint32>>)|> asExpr
581596
| ConvNullableUInt64Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<Nullable<uint64>>)|> asExpr
@@ -588,21 +603,25 @@ module LeafExpressionConverter =
588603
| ConvFloatQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<float>)|> asExpr
589604
| ConvFloat32Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<float32>)|> asExpr
590605
| ConvSByteQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<sbyte>)|> asExpr
606+
| ConvInt8Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<sbyte>)|> asExpr
591607
| ConvInt16Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<int16>)|> asExpr
592608
| ConvInt32Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<int32>)|> asExpr
593609
| ConvIntQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<int32>)|> asExpr
594610
| ConvInt64Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<int64>)|> asExpr
595611
| ConvByteQ(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<byte>)|> asExpr
612+
| ConvUInt8Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<byte>)|> asExpr
596613
| ConvUInt16Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<uint16>)|> asExpr
597614
| ConvUInt32Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<uint32>)|> asExpr
598615
| ConvUInt64Q(_,_,[x1])-> Expression.Convert(ConvExprToLinqInContext env x1, typeof<uint64>)|> asExpr
599616

600617
| CheckedConvCharQ(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<char>)|> asExpr
601618
| CheckedConvSByteQ(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<sbyte>)|> asExpr
619+
| CheckedConvInt8Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<sbyte>)|> asExpr
602620
| CheckedConvInt16Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<int16>)|> asExpr
603621
| CheckedConvInt32Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<int32>)|> asExpr
604622
| CheckedConvInt64Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<int64>)|> asExpr
605623
| CheckedConvByteQ(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<byte>)|> asExpr
624+
| CheckedConvUInt8Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<byte>)|> asExpr
606625
| CheckedConvUInt16Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<uint16>)|> asExpr
607626
| CheckedConvUInt32Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<uint32>)|> asExpr
608627
| CheckedConvUInt64Q(_,_,[x1])-> Expression.ConvertChecked(ConvExprToLinqInContext env x1, typeof<uint64>)|> asExpr

‎src/fsharp/FSharp.Core/Linq.fsi‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ namespace Microsoft.FSharp.Linq
101101
[<CompiledName("ToByte")>]
102102
val inline byte:value:Nullable< ^T >->Nullable<byte> when ^T:(static member op_Explicit:^T->byte)and default ^T:int
103103

104+
///<summary>Converts the argument to byte. This is a direct conversion for all
105+
///primitive numeric types. The operation requires an appropriate
106+
///static conversion method on the input type.</summary>
107+
///<param name="value">The input value.</param>
108+
///<returns>The converted byte</returns>
109+
[<CompiledName("ToUInt8")>]
110+
val inline uint8:value:Nullable< ^T >->Nullable<uint8> when ^T:(static member op_Explicit:^T->byte)and default ^T:int
111+
104112
///<summary>Converts the argument to signed byte. This is a direct conversion for all
105113
///primitive numeric types. The operation requires an appropriate
106114
///static conversion method on the input type.</summary>
@@ -109,6 +117,15 @@ namespace Microsoft.FSharp.Linq
109117
[<CompiledName("ToSByte")>]
110118
val inline sbyte:value:Nullable< ^T >->Nullable<sbyte> when ^T:(static member op_Explicit:^T->sbyte)and default ^T:int
111119

120+
121+
///<summary>Converts the argument to signed byte. This is a direct conversion for all
122+
///primitive numeric types. The operation requires an appropriate
123+
///static conversion method on the input type.</summary>
124+
///<param name="value">The input value.</param>
125+
///<returns>The converted sbyte</returns>
126+
[<CompiledName("ToInt8")>]
127+
val inline int8:value:Nullable< ^T >->Nullable<int8> when ^T:(static member op_Explicit:^T->sbyte)and default ^T:int
128+
112129
///<summary>Converts the argument to signed 16-bit integer. This is a direct conversion for all
113130
///primitive numeric types. The operation requires an appropriate
114131
///static conversion method on the input type.</summary>

‎src/fsharp/FSharp.Core/fslib-extra-pervasives.fs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,20 @@ module ExtraTopLevelOperators =
160160
[<CompiledName("ToDouble")>]
161161
let inlinedouble x= float x
162162

163-
[<CompiledName("ToByte")>]
163+
[<CompiledName("ToUInt8")>]
164164
let inlineuint8 x= byte x
165165

166-
[<CompiledName("ToSByte")>]
166+
[<CompiledName("ToInt8")>]
167167
let inlineint8 x= sbyte x
168168

169+
moduleChecked=
170+
171+
[<CompiledName("ToByte")>]
172+
let inlineuint8 x= Checked.byte x
173+
174+
[<CompiledName("ToSByte")>]
175+
let inlineint8 x= Checked.sbyte x
176+
169177

170178
#if FX_MINIMAL_REFLECTION// not on Compact Framework
171179
#else

‎src/fsharp/FSharp.Core/fslib-extra-pervasives.fsi‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,31 @@ module ExtraTopLevelOperators =
9292
///<summary>Converts the argument to byte.</summary>
9393
///<remarks>This is a direct conversion for all
9494
///primitive numeric types. For strings,the input is converted using <c>Byte.Parse()</c> on strings and otherwise requires a <c>ToByte</c> method on the input type.</remarks>
95-
[<CompiledName("ToByte")>]
96-
val inline uint8:value:^T->byte when ^T:(static member op_Explicit:^T->byte)and default ^T:int
95+
[<CompiledName("ToUInt8")>]
96+
val inline uint8:value:^T->uint8 when ^T:(static member op_Explicit:^T->byte)and default ^T:int
9797

9898
///<summary>Converts the argument to signed byte.</summary>
9999
///<remarks>This is a direct conversion for all
100100
///primitive numeric types. For strings,the input is converted using <c>SByte.Parse()</c> with InvariantCulture settings.
101101
///Otherwise the operation requires and invokes a <c>ToSByte</c> method on the input type.</remarks>
102-
[<CompiledName("ToSByte")>]
103-
val inline int8:value:^T->sbyte when ^T:(static member op_Explicit:^T->sbyte)and default ^T:int
102+
[<CompiledName("ToInt8")>]
103+
val inline int8:value:^T->int8 when ^T:(static member op_Explicit:^T->int8)and default ^T:int
104+
105+
106+
module Checked=
107+
108+
///<summary>Converts the argument to byte.</summary>
109+
///<remarks>This is a direct,checked conversion for all
110+
///primitive numeric types. For strings,the input is converted using <c>Byte.Parse()</c> on strings and otherwise requires a <c>ToByte</c> method on the input type.</remarks>
111+
[<CompiledName("ToByte")>]
112+
val inline uint8:value:^T->byte when ^T:(static member op_Explicit:^T->byte)and default ^T:int
113+
114+
///<summary>Converts the argument to signed byte.</summary>
115+
///<remarks>This is a direct,checked conversion for all
116+
///primitive numeric types. For strings,the input is converted using <c>SByte.Parse()</c> with InvariantCulture settings.
117+
///Otherwise the operation requires and invokes a <c>ToSByte</c> method on the input type.</remarks>
118+
[<CompiledName("ToSByte")>]
119+
val inline int8:value:^T->sbyte when ^T:(static member op_Explicit:^T->sbyte)and default ^T:int
104120

105121

106122
///<summary>Builds a read-only lookup table from a sequence of key/value pairs. The key objects are indexed using generic hashing and equality.</summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp