Isocurves for Trimmed Surfaces_C#

I am struggling to understand how the isocurve component in grasshopper works on trimmed surface.
I used RhinoCommon to achieve similar result like GH isocurve component but I was unable to get same result.
Thanks in advance. attached images.
Pic 1) Grasshopper result

Pic 2) C# script result…What do I need to do before using Surface.IsoCurve() method???

A surface with trims is not a surface anymore but a brepface. when you apply a surface method it is automatically ignoring the trims since it is treated as a surface.
Probably this one is the right method: