I am extracting a bool value from a (non-generic, heterogeneous) collection.
The as operator may only be used with reference types, so it is no
If the goal is to have true only if the raw object is boolean 'true' then one-liner (rawValue as bool?)?? false will do:
object rawValue=null
(rawValue as bool?)?? false
false
rawValue="some string"
(rawValue as bool?)?? false
false
rawValue=true
(rawValue as bool?)?? false
true
rawValue="true"
(rawValue as bool?)?? false
false
rawValue=false
(rawValue as bool?)?? false
false
rawValue=""
(rawValue as bool?)?? false
false
rawValue=1
(rawValue as bool?)?? false
false
rawValue=new Dictionary()
(rawValue as bool?)?? false
false`