4. $f(x)$ is a function defined on $\mathbf{R}$, and for any $x$ it satisfies $f(x+1)=-f(x)$. It is known that when $x \in(2,3]$, $f(x)=x$. Then, when $x \in(-2,0]$, the expression for $f(x)$ is ( ).
(A) $f(x)=x+4$
(B) $f(x)=\left\{\begin{array}{ll}x+4, & x \in(-2,-1] \\ -x+2, & x \in(-1,0]\end{array}\right.$
(C) $f(x)=\left\{\begin{array}{ll}x+4, & x \in(-2,-1] \\ -x-3, & x \in(-1,0]\end{array}\right.$
(D) $f(x)=\left\{\begin{array}{ll}-x-1, & x \in(-2,-1] \\ -x-3, & x \in(-1,0]\end{array}\right.$