7. Given that $f(n)$ is a function defined on the set of positive integers, and $f(1)=2$.
When $n$ is even, $f(n)=f(n-1)+2$;
When $n$ is an odd number greater than 1,
$$
f(n)=f(n-2)+2 \text {. }
$$

Then the value of $f(2017)$ is ( ).
(A) 2017
(B) 2018
(C) 4034
(D) 4035
(E) 4036
7. B.

Obviously, when $n$ is a positive integer,
$$
f(2 n+1)=f(2 n-1)+2 \text{. }
$$

Let $a_{n}=f(2 n-1)$, i.e., $a_{n+1}=a_{n}+2$.
Then $\left\{a_{n}\right\}$ is an arithmetic sequence with the first term $a_{1}=f(1)=2$ and a common difference of 2, i.e., $a_{n}=2 n$.
$$
\begin{array}{l}
\text{ Hence } f(2017)=f(1009 \times 2-1) \\
=a_{1009}=2018 \text{. }
\end{array}
$$