如何将这个 C# class 翻译成 UML

How to translate this C# class into UML

如何为给定的 C# 代码创建 UML Class 图

// A class for two-dimensional objects.
class TwoDShape {
    double pri_width;
    double pri_height;
    // Properties for Width and Height.
    public double Width {
        get { return pri_width; }
        set { pri_width = value < 0 ? -value : value; }
    }
    public double Height {
        get { return pri_height; }
        set { pri_height = value < 0 ? -value : value; }
    }
    public void ShowDim() {
        Console.WriteLine("Width and height are " +
        Width + " and " + Height);
    }
}

如何在 class 图表中表示上述 class 属性宽度和高度? UML 规范没有说明 C# 代码中这种 class 表示形式。

这就是 Sparx Enterprise Architect 使用“代码工程 -> 从源文件导入

回答您问题的方式

UML 是而且必须是语言不可知论者。 所以对我来说更合乎逻辑的答案是宽度和高度是 UML 属性。

然后建模工具必须添加构造型或注释以区分宽度和 pri_width UML 属性。

下面是来自 Modelio Tool

的另一张截图