Generates AreaUtils class which provides helpers to calculate area of geometry shapes defined in project. It allows to:
- Easely add new shapes and then automaticaly area helpers for new shapes will be generated
- Avoid heap allocation when only need to calculate area
- Find classes derived from base class Shape
- Get all properties used in GetArea method
- Get constructor which initialize all this properties
- Get constructor parameters which wil be user as htlper method parameters
- Get all statements from constructor (validation & assignment)
- Get method body depending is it block or lambda
- Build helper method using pattern:
public static double Get{*className*}Area({constructor parameters})
{
{ all statements from constructor }
{ GetArea method body }
}
usingGeometryLib.Helpers;namespaceAreaLib.Utils{publicstaticclassAreaUtils{publicstaticdoubleGetCircleArea(doubleradius){varRadius=Guard.AgainstNegativeOrZero(radius);returnMath.PI*Math.Pow(Radius,2);}publicstaticdoubleGetTriangleArea(doublea,doubleb,doublec){varA=Guard.AgainstNegativeOrZero(a);varB=Guard.AgainstNegativeOrZero(b);varC=Guard.AgainstNegativeOrZero(c);Guard.AgainstIncorrectTriangleSides(a,b,c);doublep=(A+B+C)/2;returnMath.Sqrt(p*(p-A)*(p-B)*(p-C));}}}