我有两个功能,仅在某些条件下有所不同。能统一吗?

I've got two functions that differ only by some condition. Can it be unified?

所以我有这两个方法:

    public static string Figure2D()
    {
        dynamic shapeValue;
        do
        {
            shapeValue = Presentation.Present();
        }
        while (shapeValue.Is3D);
        return shapeValue.ToString("R");
    }

    public static string Figure3D()
    {
        dynamic shapeValue;
        do
        {
            shapeValue = Presentation.Present();
        }
        while (!shapeValue.Is3D);
        return shapeValue.ToString("R");
    }

它们之间的唯一区别是 while 条件。如何将这两个合并为一个函数?传递参数值可能是必要的并且可以接受,但我希望保持简短。有什么想法吗?

怎么样

public static string Figure(Predicate<dynamic> p)
    {
        dynamic shapeValue;
        do
        {
            shapeValue = Presentation.Present();
        }
        while (p(shapeValue));
        return shapeValue.ToString("R");
    }