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.$
4. (C).
$$
\begin{array}{l}
\because f(x+1)=-f(x), \\
\quad \therefore f(x+2)=-f(x+1)=f(x) .
\end{array}
$$

Thus, $f(x)$ is a periodic function with a period of 2. When $x \in (2,3]$, we have $f(x)=x$. When $x \in (3,4]$, $x-1 \in (2,3]$, so $f(x-1)=x-1$. Therefore, $f(x)=-f(x-1)=1-x$, hence $f(x)=\left\{\begin{array}{ll}x, & x \in (2,3] \\ 1-x, & x \in (3,4]\end{array}\right.$, which means when $x \in (-2,0]$, $x+4$ $\in (2,4]=(2,3] \cup (3,4]$, we have
$$
\begin{array}{l}
f(x)=f(x+4) \\
=\left\{\begin{array}{ll}
x+4, & x \in (-2,-1] \\
1-(x+4)=-x-3 . & x \in (-1,0]
\end{array}\right.
\end{array}
$$