Example 10 If $\cos \alpha+2 \sin \alpha=-\sqrt{5}$, then $\tan \alpha=$ （）.
A. $\frac{1}{2}$
B. 2
C. $-\frac{1}{2}$
D. -2
From the given conditions and Cauchy-Schwarz inequality, we have
$$\begin{array}{l}
5=(1 \times \cos \alpha+2 \times \sin \alpha)^{2} \\
\leqslant\left(1^{2}+2^{2}\right)\left(\cos ^{2} \alpha+\sin ^{2} \alpha\right)=5
\end{array}$$

Equality holds if and only if $\frac{\cos \alpha}{1}=\frac{\sin \alpha}{2}$, i.e., $\tan \alpha=2$. Therefore, the answer is B.