How to get length of animation in Mecanim?

Note: I’m using Mecanim, so please don’t copy and paste legacy codes.

I’d like to know a clean/correct way to get the length of animation in Mecanim.

The problem is that there is no approach to access a specific state in Animator Controller. The script interface only provides access to current state and next state.

Although this answer can get “state”, it does not provide the length like AnimatorStateInfo does.

Is there any good way to this?

float value = anim.GetCurrentAnimatorStateInfo(0).length;