Cut the polyline with boundary rectangle c#

Hi,

This is exactly replicating the Trim with Brep component.
Build a closed box from the rectangle, test for intersections, shatter the curve (curve.Split()) and select pieces that have their middle inside the box.