I'd like to be able to get the Value of a union using the syntax of Value() (i.e. using the class name), but without the risk of throwing an exception. I have 3 approaches in mind, and before I start coding I was hoping you could weigh in on which way I should go.
- Add a
Option<T> GetValue<T>() which returns Some if the union is of type T, else None
- Add a
bool TryGetValue<T>(out value) which returns a bool as to whether it succeeded and the actual value in the out param
- Add a
bool HasValue<T>() which just returns a bool for whether this union is of type T
Do you have a preferred approach?
Thank you,
Gavin Steyn
I'd like to be able to get the Value of a union using the syntax of Value() (i.e. using the class name), but without the risk of throwing an exception. I have 3 approaches in mind, and before I start coding I was hoping you could weigh in on which way I should go.
Option<T> GetValue<T>()which returns Some if the union is of type T, else Nonebool TryGetValue<T>(out value)which returns a bool as to whether it succeeded and the actual value in the out parambool HasValue<T>()which just returns a bool for whether this union is of type TDo you have a preferred approach?
Thank you,
Gavin Steyn