[C# rhino7] How to drill holes in surfaces

hi guys .As shown in the figure, I want to use curve to drill holes in the surface. What function should I use to achieve this goal .Can you provide some useful solutions?

hole.3dm (298.7 KB)

above is the test file and I have tried some methods But can not work

 GetObject go = new GetObject();

 go.GeometryFilter = ObjectType.Brep | ObjectType.Extrusion;
 go.AcceptNumber(true, false);
 go.SetCommandPrompt("select Brep");
 GetResult Res = go.GetMultiple(1, 0);

 if (Res == GetResult.Cancel || go.ObjectCount == 0)
     return Result.Failure;
      
 List<ObjRef> SelectedBoundaryRefs = new List<ObjRef>();
 Result Res2 = RhinoGet.GetMultipleObjects("select curve", true, ObjectType.Curve, out ObjRef[] CeilBoundaryRefs);
 if (Res2 == Result.Success)
 {
     SelectedBoundaryRefs.AddRange(CeilBoundaryRefs);
 }
 SelectedBoundaryRefs = SelectedBoundaryRefs.Distinct<ObjRef>(new ObjRefComparer()).ToList();
 if (SelectedBoundaryRefs.Count == 0)
 {
     return Result.Failure;
 }
 else
 {
     double tolerance = Doc.ActiveDoc.ModelAbsoluteTolerance;
     RhinoObject brepobj = go.Objects()[0].Object();  
     Extrusion Extr =  brepobj.Geometry as Extrusion;
     Brep br = Extr.ToBrep(false);
     Curve cur = SelectedBoundaryRefs[0].Curve();
     //method1  res Length=0
     Brep[] breps = Rhino.Geometry.Brep.CreatePlanarBreps(cur, tolerance);
     Brep curbrep = breps[0];
     Brep[]  res = br.Trim(curbrep, tolerance);
     if(res.Length>0)
     {
         doc.Objects.Add(res[0]);
     }
     else
     {
         doc.Objects.Add(curbrep);
     }
     //method2   CeilPiece Length=1  But the result is not what i want 
     Surface surface = Extrusion.CreateExtrusion(cur, new Vector3d(0,0,-10));
     Rhino.Geometry.Brep brep = Rhino.Geometry.Brep.CreateFromSurface(surface);
     Brep Boolgeo = brep.CapPlanarHoles(tolerance);
     Brep[] CeilPiece = Brep.CreateBooleanDifference(br, Boolgeo, tolerance);
     if(CeilPiece.Length>0)
     {
         doc.Objects.Add(CeilPiece[0]);
     }
     else
     {
         doc.Objects.Add(Boolgeo);
     }
 }

I urgently need your help . thank you

Is this useful for your application

var res = RhinoGet.GetMultipleObjects("Select Breps", false, ObjectType.Brep | ObjectType.Extrusion, out var bRefs);
if (res != Result.Success) return res;

res = RhinoGet.GetMultipleObjects("Select curves", false, ObjectType.Curve, out var cRefs);
if (res != Result.Success) return res;

Brep[] breps = bRefs.Select(b => b.Brep()).ToArray();
Curve[] curves = cRefs.Select(c => c.Curve()).ToArray();

foreach(var brep in breps)
{
    List<Curve> projectedCurves = new List<Curve>();
    // project curves in positive and negative Z-direction
    foreach(var curve in curves)
    {
        Curve[] projected = Curve.ProjectToBrep(curve, brep, -Vector3d.ZAxis, doc.ModelAbsoluteTolerance);
        if (projected != null && projected.Length == 1)
        {
            projectedCurves.Add(projected[0]);
        }
        projected = Curve.ProjectToBrep(curve, brep, Vector3d.ZAxis, doc.ModelAbsoluteTolerance);
        if (projected != null && projected.Length == 1)
        {
            projectedCurves.Add(projected[0]);
        }        
    }

    // split the brep with the projected curves
    Brep[] pieces = brep.Split(projectedCurves, doc.ModelAbsoluteTolerance);
    
    // select the piece that does not have approximately the bounding box 
    // of one of the cutting curves. This is the bit with the holes trimmed in.
    foreach(var piece in pieces) 
    {
        BoundingBox pieceBB = piece.GetBoundingBox(true);
        bool matched = false;
        foreach(var projected in projectedCurves)
        {
            BoundingBox crvBB = projected.GetBoundingBox(true);
            if (pieceBB.Min.DistanceTo(crvBB.Min) < 10*doc.ModelAbsoluteTolerance && 
                pieceBB.Max.DistanceTo(crvBB.Max) < 10*doc.ModelAbsoluteTolerance) {
                    matched = true;
                    break;
                }
        } 

        if (!matched) doc.Objects.Add(piece);
    }
}

so, we needed to use the Split() function .Thank you very much for your help.