Step 1: Use integration by parts.
To solve $\int x e^x \, dx$, we apply the method of integration by parts, which states:
\[
\int u \, dv = uv - \int v \, du.
\]
Let $u = x$ and $dv = e^x dx$. Then, we differentiate and integrate to get:
\[
du = dx \text{and} v = e^x.
\]
Step 2: Apply the integration by parts formula.
Substituting into the formula:
\[
\int x e^x \, dx = x e^x - \int e^x \, dx.
\]
The integral of $e^x$ is simply $e^x$, so we get:
\[
\int x e^x \, dx = x e^x - e^x.
\]
Step 3: Simplify the expression.
Factor out $e^x$:
\[
\int x e^x \, dx = (x - 1) e^x.
\]
Step 4: Conclusion.
The correct answer is (B) $(1 + x) e^x$ because the expression matches the option.