>>106439023
It looks a bit like extension in Beef
// interface
interface Shape
{
public float Area();
public float Perimeter();
public float AreaPerPerimeter() => Area() / Perimeter();
}
// type declaration
struct Cirlcle : this(float radius);
struct Rectangle : this(float width, float height);
//extending Circle by implementing the Shape interface
extension Cirlcle : Shape
{
public float Area() => radius * Math.PI_f * Math.PI_f;
public float Perimeter() => radius * 2 * Math.PI_f;
}
// doing the same with Rectangle
extension Rectangle : Shape
{
public float Area() => width * height;
public float Perimeter() => (width * height) * 2;
}
public static
{
// extending every type that implemented Shape
public static void Print<T>(this T shape) where T : Shape
{
Console.WriteLine("Area per perimeter of {} = {}", shape.GetType(), shape.AreaPerPerimeter());
}
// add a Square method to any types with the * operator
public static T Square<T>(this T n) where T : operator T * T
{
return n * n;
}
}