Reflection to find out if property is of option type

Viewed 1068

I am filling some object's fields with data using reflection. As my object is of F# type, it has some Option fields. In case of option

property.SetValue(object, newValue)

reasonably fails, because it needs

property.SetValue(object, Some(newValue))

Hence, I am trying to find out if a property is of type Option. I can do it like this:

let isOption (p:PropertyInfo) = p.PropertyType.Name.StartsWith("FSharpOption")

But there must be some better way, must it not? And I must say it is strange to me that there's no method IsOption in FSharpType.

1 Answers
Related