Код: Выделить всё
public readonly struct Shape
{
public void Render (Graphics graphics)
{
// Do complex manipulation to draw the shape using the `graphics` object.
graphics.DrawLine(Pens.Red, this.Point1, this.Point2);
graphics.DrawLine(Pens.Red, this.Point2, this.Point3);
...
}
}
< /code>
и вызовный код из приложения Winforms: < /p>
private void PictureBox_Paint (object? sender, PaintEventArgs e)
{
var shape = new Shape(...);
shape.Render(e.Graphics);
}
Я мог бы использовать указания компилятора здесь, чтобы гарантировать, что этот код существует только в рамках Winforms , но это тоже не будет делать, так как вызовный код может быть для Render (Graphics). это, чтобы классы слабо связаны?
Подробнее здесь: https://stackoverflow.com/questions/796 ... pendencies