How to Use a Complex Type in a Conditional
I am building a basic authorization framework, and I have really liked the use of it so far.
It basically looks something like this
The result that I get back is not actually a boolean, as you might thing. It’s a complex type that I built so I could not only determine if authorization was successful or not, but also why not.
So you can do this:
and you can also do this:
WhyNot will actually give you back a list of Reasons, which you can then use to inform the system (or user) why they can’t do something.
So what’s the problem? Sometimes I just don’t care why not, I just want to do the check quickly and be done with it, which makes me want to do something like this instead:
This won’t compile, because my complex type can’t resolve to a bool. Not to worry, though, implicit operator to the rescue:
1 2 3 4 5 6 7 8 9 10
Next post I’ll talk about how I do the same thing for outputting the reasons implicitly.