提交 36050db5 编写于 作者: K Kevin Ransom (msft) 提交者: GitHub

Merge pull request #1467 from forki/isNotNull

Cleanup isNotNull
......@@ -270,11 +270,17 @@ type internal CompileThreadStatic =
static member BuildPhaseUnchecked with get() = CompileThreadStatic.buildPhase (* This can be a null value *)
static member BuildPhase
with get() = if box CompileThreadStatic.buildPhase <> null then CompileThreadStatic.buildPhase else (assert false; BuildPhase.DefaultPhase)
with get() =
match box CompileThreadStatic.buildPhase with
| null -> assert false; BuildPhase.DefaultPhase
| _ -> CompileThreadStatic.buildPhase
and set v = CompileThreadStatic.buildPhase <- v
static member ErrorLogger
with get() = if box CompileThreadStatic.errorLogger <> null then CompileThreadStatic.errorLogger else !uninitializedErrorLoggerFallback
with get() =
match box CompileThreadStatic.errorLogger with
| null -> !uninitializedErrorLoggerFallback
| _ -> CompileThreadStatic.errorLogger
and set v = CompileThreadStatic.errorLogger <- v
......
......@@ -2546,6 +2546,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2412,6 +2412,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2576,6 +2576,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2551,6 +2551,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2553,6 +2553,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2564,6 +2564,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2551,6 +2551,7 @@ Microsoft.FSharp.Core.Operators+Unchecked: System.Type GetType()
Microsoft.FSharp.Core.Operators+Unchecked: T DefaultOf[T]()
Microsoft.FSharp.Core.Operators+Unchecked: T Unbox[T](System.Object)
Microsoft.FSharp.Core.Operators: Boolean Equals(System.Object)
Microsoft.FSharp.Core.Operators: Boolean IsNotNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean IsNull[T](T)
Microsoft.FSharp.Core.Operators: Boolean Not(Boolean)
Microsoft.FSharp.Core.Operators: Boolean op_Equality[T](T, T)
......
......@@ -2228,7 +2228,7 @@ namespace Microsoft.FSharp.Control
event.RemoveHandler handle
if args.Cancelled then
ccont (new OperationCanceledException())
elif args.Error <> null then
elif isNotNull args.Error then
econt args.Error
else
cont (result args)
......@@ -2515,8 +2515,8 @@ namespace Microsoft.FSharp.Control
| Some res -> return res }
interface System.IDisposable with
member x.Dispose() =
if pulse <> null then (pulse :> IDisposable).Dispose()
member __.Dispose() =
if isNotNull pulse then (pulse :> IDisposable).Dispose()
#if DEBUG
member x.UnsafeContents =
......
......@@ -3804,6 +3804,12 @@ namespace Microsoft.FSharp.Core
| null -> true
| _ -> false
[<CompiledName("IsNotNull")>]
let inline isNotNull (value : 'T) =
match value with
| null -> false
| _ -> true
[<CompiledName("Raise")>]
let raise (e: exn) = (# "throw" e : 'T #)
......
......@@ -2150,6 +2150,12 @@ namespace Microsoft.FSharp.Core
/// <returns>True when value is null, false otherwise.</returns>
[<CompiledName("IsNull")>]
val inline isNull : value:'T -> bool when 'T : null
/// <summary>Determines whether the given value is not null.</summary>
/// <param name="value">The value to check.</param>
/// <returns>True when value is not null, false otherwise.</returns>
[<CompiledName("IsNotNull")>]
val inline isNotNull : value:'T -> bool when 'T : null
/// <summary>Throw a <c>System.Exception</c> exception.</summary>
/// <param name="message">The exception message.</param>
......
......@@ -149,21 +149,21 @@ module internal Impl =
let tryFindCompilationMappingAttributeFromType (typ:Type) =
let assem = typ.Assembly
if assem <> null && assem.ReflectionOnly then
if isNotNull assem && assem.ReflectionOnly then
tryFindCompilationMappingAttributeFromData ( typ.GetCustomAttributesData())
else
tryFindCompilationMappingAttribute ( typ.GetCustomAttributes (typeof<CompilationMappingAttribute>,false))
let tryFindCompilationMappingAttributeFromMemberInfo (info:MemberInfo) =
let assem = info.DeclaringType.Assembly
if assem <> null && assem.ReflectionOnly then
if isNotNull assem && assem.ReflectionOnly then
tryFindCompilationMappingAttributeFromData (info.GetCustomAttributesData())
else
tryFindCompilationMappingAttribute (info.GetCustomAttributes (typeof<CompilationMappingAttribute>,false))
let findCompilationMappingAttributeFromMemberInfo (info:MemberInfo) =
let assem = info.DeclaringType.Assembly
if assem <> null && assem.ReflectionOnly then
if isNotNull assem && assem.ReflectionOnly then
findCompilationMappingAttributeFromData (info.GetCustomAttributesData())
else
findCompilationMappingAttribute (info.GetCustomAttributes (typeof<CompilationMappingAttribute>,false))
......
......@@ -83,7 +83,7 @@ module internal ReflectionAdapters =
| _ -> raise (AmbiguousMatchException())
let canUseAccessor (accessor : MethodInfo) nonPublic =
box accessor <> null && (accessor.IsPublic || nonPublic)
isNotNull(box accessor) && (accessor.IsPublic || nonPublic)
type System.Type with
member this.GetTypeInfo() = IntrospectionExtensions.GetTypeInfo(this)
......@@ -124,7 +124,7 @@ module internal ReflectionAdapters =
let bindingFlags = defaultArg bindingFlags publicFlags
(if isDeclaredFlag bindingFlags then this.GetTypeInfo().DeclaredProperties else this.GetRuntimeProperties())
|> Seq.filter (fun pi->
let mi = if pi.GetMethod <> null then pi.GetMethod else pi.SetMethod
let mi = match pi.GetMethod with | null -> pi.SetMethod | _ -> pi.GetMethod
if mi = null then false
else isAcceptable bindingFlags mi.IsStatic mi.IsPublic
)
......@@ -179,8 +179,9 @@ module internal ReflectionAdapters =
#if FX_RESHAPED_REFLECTION_CORECLR
member this.InvokeMember(memberName, bindingFlags, _binder, target:obj, arguments:obj[], _cultureInfo) =
let m = this.GetMethod(memberName, (arguments |> Seq.map(fun x -> x.GetType()) |> Seq.toArray), bindingFlags)
if m <> null then m.Invoke(target, arguments)
else raise <| System.MissingMethodException(String.Format("Method '{0}.{1}' not found.", this.FullName, memberName))
match m with
| null -> raise <| System.MissingMethodException(String.Format("Method '{0}.{1}' not found.", this.FullName, memberName))
| _ -> m.Invoke(target, arguments)
#endif
member this.IsGenericType = this.GetTypeInfo().IsGenericType
member this.IsGenericTypeDefinition = this.GetTypeInfo().IsGenericTypeDefinition
......
......@@ -713,7 +713,7 @@ namespace Microsoft.FSharp.Text.StructuredFormat
let ty = obj.GetType()
#if FX_ATLEAST_PORTABLE
let prop = ty.GetProperty(name, (BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.NonPublic))
if prop <> null then prop.GetValue(obj,[||])
if isNotNull prop then prop.GetValue(obj,[||])
#if FX_NO_MISSINGMETHODEXCEPTION
// Profile 7, 47, 78 and 259 raise MissingMemberException
else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册