From a user's perspective, I want to cast an object to a type, and get a null if the object is not of that type. Then I can use the ?. operator to get a member out of the object, in case of success, or null otherwise. To me, it is natural to express this in the following way:
MemberType get extractedMember => (object as? Type)?.member;
This, of course, is wishful thinking, since there is no 'as?' operator. Currently, the best way to express this is (parenthesis subject to taste, formatting as per dartfmt):
MemberType get extractedMember => (object is Type)
? (object as Type).member
: null;
Putting aside for a moment the amount of work to the dev tools necessary to support such feature, I am wondering if there any problems with it from language perspective?
Thanks,
- Stan