Skip to content

Instantly share code, notes, and snippets.

@ltOgt
Last active February 2, 2022 15:40
Show Gist options
  • Save ltOgt/04212037dca1d7a68b4e89dddc750bbd to your computer and use it in GitHub Desktop.
Save ltOgt/04212037dca1d7a68b4e89dddc750bbd to your computer and use it in GitHub Desktop.
void main() {
dynamic t = TC();
print(ifHasMethodElse(() => t.code, ""));
}
ifHasMethodElse(Function closureWithCall, dynamic elseThis) {
try {
return closureWithCall();
} catch (NoSuchMethodError, e) {
return elseThis;
}
}
class TC {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment