@@ -143,8 +143,7 @@ let inline (|OptionNone|_|) (e: Expression) =
143143 match e with
144144 | MethodCall( None, MethodWithName( " get_None" ),[]) ->
145145 match e with
146- | :? MethodCallExpression as e when ( e.Method.DeclaringType.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpOption`1" )
147- || e.Method.DeclaringType.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpValueOption`1" )) -> ValueSome()
146+ | :? MethodCallExpression as e when Common.Utilities.isOpt e.Method.DeclaringType -> ValueSome()
148147 | _ -> ValueNone
149148 | _ -> ValueNone
150149
@@ -157,8 +156,7 @@ let (|NullConstant|_|) (e:Expression) =
157156let (| ConstantOrNullableConstant | _ |) ( e : Expression ) =
158157 match e.NodeType, e with
159158 | ExpressionType.Constant, (:? ConstantExpression as ce) ->
160- if ce.Type.IsGenericType && ( ce.Type.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpOption`1" )
161- || ce.Type.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpValueOption`1" )) then
159+ if Common.Utilities.isOpt ce.Type then
162160 match ce.Type.GetProperty( " Value" ) .GetValue( ce.Value,[||]) with
163161 | null -> Some( Some( ce.Value))
164162 | optVal -> Some( Some( optVal))
@@ -223,11 +221,10 @@ let (|OptionalFSharpOptionValue|) (e:Expression) =
223221 match e.NodeType, e with
224222 | ExpressionType.MemberAccess, ( :? MemberExpression as e) ->
225223 match e.Member with
226- | :? PropertyInfo as p when p.Name = " Value" && ( e.Member.DeclaringType.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpOption`1" )
227- || e.Member.DeclaringType.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpValueOption`1" )) -> e.Expression
224+ | :? PropertyInfo as p when p.Name = " Value" && Common.Utilities.isOpt e.Member.DeclaringType -> e.Expression
228225 | _ -> upcast e
229226 | ExpressionType.Call, OptionalCopyOfStruct ( :? MethodCallExpression as e)
230- when e.Method.Name = " Some" && ( e.Method.DeclaringType.FullName.StartsWith ( " Microsoft.FSharp.Core.FSharpOption`1 " ) || e.Method.DeclaringType.FullName.StartsWith ( " Microsoft.FSharp.Core.FSharpValueOption`1 " )) -> e.Arguments.[ 0 ]
227+ when e.Method.Name = " Some" && Common.Utilities.isOpt e.Method.DeclaringType -> e.Arguments.[ 0 ]
231228 | _, OptionalCopyOfStruct n -> n
232229
233230let (| AndAlso | _ |) ( e : Expression ) =
@@ -367,8 +364,8 @@ let integerTypes = [| typeof<Int32>; typeof<Int64>; typeof<Int16>; typeof<int8>;
367364 typeof< ValueOption< Int32>>; typeof< ValueOption< Int64>>; typeof< ValueOption< Int16>>; typeof< ValueOption< int8>>; typeof< ValueOption< UInt32>>; typeof< ValueOption< UInt64>>; typeof< ValueOption< UInt16>>; typeof< ValueOption< uint8>>;|]
368365
369366let intType ( typ : Type ) =
370- if ( not ( isNull typ)) && typ.IsGenericType && typ.GetGenericTypeDefinition () = typedefof < Option <_>> then typeof< Option< int>>
371- elif ( not ( isNull typ)) && typ.IsGenericType && typ.GetGenericTypeDefinition () = typedefof < ValueOption <_>> then typeof< ValueOption< int>>
367+ if ( not ( isNull typ)) && Common.Utilities.isCOpt typ then typeof< Option< int>>
368+ elif ( not ( isNull typ)) && Common.Utilities.isVOpt typ then typeof< ValueOption< int>>
372369 else typeof< int>
373370
374371let inline internal getRightFromOp ( right : Expression ) =
@@ -396,13 +393,13 @@ let rec (|SqlColumnGet|_|) (ex:Expression) =
396393 // These are aggregations, e.g. GROUPBY, HAVING-clause
397394 | ExpressionType.MemberAccess, ( :? MemberExpression as me) when
398395 ( not ( isNull me.Expression || isNull me.Expression.Type || isNull me.Expression.Type.Name)) &&
399- me.Expression.Type.Name.StartsWith ( " IGrouping " ) ->
396+ Common.Utilities.isGrp me.Expression.Type ->
400397 match me.Member with
401398 | :? PropertyInfo as p when p.Name = " Key" -> Some( String.Empty, GroupColumn ( KeyOp " " , SqlColumnType.KeyColumn( " Key" )), p.DeclaringType)
402399 | _ -> None
403400 | ExpressionType.Call, ( :? MethodCallExpression as e) when ( not ( isNull e.Arguments)) && e.Arguments.Count = 1 &&
404401 not ( isNull e.Arguments.[ 0 ] || isNull e.Arguments.[ 0 ]. Type || isNull e.Arguments.[ 0 ]. Type.Name) &&
405- e.Arguments.[ 0 ]. Type.Name.StartsWith ( " IGrouping " ) ->
402+ Common.Utilities.isGrp e.Arguments.[ 0 ]. Type ->
406403 if e.Arguments.[ 0 ]. NodeType = ExpressionType.Parameter then
407404 let pn = match e.Arguments.[ 0 ] with :? ParameterExpression as p -> p.Name | _ -> e.Method.Name
408405 match e.Method.Name with
@@ -566,7 +563,7 @@ let rec (|SqlColumnGet|_|) (ex:Expression) =
566563
567564 match be.Left, be.Right with
568565 | OptionalConvertOrTypeAs( OptionalFSharpOptionValue( SqlColumnGet( alias, col, typ))) as p1, OptionalConvertOrTypeAs( Constant( constVal, constTyp))
569- when ( Type.(=)( p1.Type, constTyp) || ( p1.Type.IsGenericType && ( p1.Type.GetGenericTypeDefinition () = typedefof < Option <_>> || p1.Type.GetGenericTypeDefinition () = typedefof < ValueOption <_>>) && p1.Type.GenericTypeArguments.[ 0 ] = constTyp )
566+ when ( Type.(=)( p1.Type, constTyp) || ( Common.Utilities.isOpt p1.Type && p1.Type.GenericTypeArguments.[ 0 ] = constTyp )
570567 || Type.(=)( be.Left.Type, be.Right.Type)) -> // Support only numeric and string math
571568 match p1.Type with
572569 | t when ( operation = " +" && ( Type.(=)( t, typeof< System.String>) || Type.(=)( t, typeof< System.Char>) || Type.(=)( t, typeof< Option< System.String>>) || Type.(=)( t, typeof< Option< System.Char>>) || Type.(=)( t, typeof< ValueOption< System.Char>>))) ->
@@ -576,7 +573,7 @@ let rec (|SqlColumnGet|_|) (ex:Expression) =
576573 Some( alias, CanonicalOperation( CanonicalOp.BasicMath( operation, constVal), col), typ)
577574 | _ -> None
578575 | OptionalConvertOrTypeAs( Constant( constVal, constTyp)), ( OptionalConvertOrTypeAs( OptionalFSharpOptionValue( SqlColumnGet( alias, col, typ))) as p1)
579- when ( Type.(=)( p1.Type, constTyp) || ( p1.Type.IsGenericType && ( p1.Type.GetGenericTypeDefinition () = typedefof < Option <_>> || p1.Type.GetGenericTypeDefinition () = typedefof < ValueOption <_>>) && p1.Type.GenericTypeArguments.[ 0 ] = constTyp )
576+ when ( Type.(=)( p1.Type, constTyp) || ( Common.Utilities.isOpt p1.Type && p1.Type.GenericTypeArguments.[ 0 ] = constTyp )
580577 || Type.(=)( be.Left.Type, be.Right.Type)) -> // Support only numeric and string math
581578 match p1.Type with
582579 | t when ( operation = " +" && ( Type.(=)( t, typeof< System.String>) || Type.(=)( t, typeof< System.Char>) || Type.(=)( t, typeof< Option< System.String>>) || Type.(=)( t, typeof< Option< System.Char>>) || Type.(=)( t, typeof< ValueOption< System.String>>) || Type.(=)( t, typeof< ValueOption< System.Char>>))) ->
@@ -587,8 +584,8 @@ let rec (|SqlColumnGet|_|) (ex:Expression) =
587584 | _ -> None
588585 | OptionalConvertOrTypeAs( OptionalFSharpOptionValue( SqlColumnGet( aliasLeft, colLeft, typLeft))) as p1, ( OptionalConvertOrTypeAs( OptionalFSharpOptionValue( SqlColumnGet( aliasRight, colRight, typRight))) as p2)
589586 when ( Type.(=)( p1.Type, p2.Type) ||
590- ( p1.Type.IsGenericType && ( p1.Type.GetGenericTypeDefinition () = typedefof < Option <_>> || p1.Type.GetGenericTypeDefinition () = typedefof < ValueOption <_>>) && p1.Type.GenericTypeArguments.[ 0 ] = p2.Type ) ||
591- ( p2.Type.IsGenericType && ( p2.Type.GetGenericTypeDefinition () = typedefof < Option <_>> || p2.Type.GetGenericTypeDefinition () = typedefof < ValueOption <_>>) && p2.Type.GenericTypeArguments.[ 0 ] = p1.Type ) ||
587+ ( Common.Utilities.isOpt p1.Type && p1.Type.GenericTypeArguments.[ 0 ] = p2.Type ) ||
588+ ( Common.Utilities.isOpt p2.Type && p2.Type.GenericTypeArguments.[ 0 ] = p1.Type ) ||
592589 Type.(=)( be.Left.Type, be.Right.Type)) ->
593590 let opFix =
594591 match p1.Type with
@@ -733,8 +730,7 @@ and (|SimpleCondition|_|) exp =
733730 if isNull invokedResult then handleNullCompare()
734731 else
735732 let retType = invokedResult.GetType()
736- if retType.IsGenericType && ( retType.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpOption" ) ||
737- retType.FullName.StartsWith( " Microsoft.FSharp.Core.FSharpValueOption" )) then
733+ if Common.Utilities.isOpt retType then
738734 let gotVal = retType.GetProperty( " Value" ) // Option type Some should not be SQL-parameter.
739735 match gotVal.GetValue( invokedResult, [||]) with
740736 | null -> handleNullCompare()
0 commit comments