i looking best solution in web api on how evaluate mathematical formulas , set result/output in property field.
lets have following entity 2 properties. likewise have many properties different formulas.
public class domainentites { public float centimetertometer{ get; set; } public float inchtofeet { get; set; } }
i have formulas below saved in database.
key formula ---- ------- c_m * 1000
my idea pass key , execute formula whereever applicable. can reduce complexity of code , make generic.
public class domainentites { [unitconversion(key="c_m")] public float centimetertometer{ get; set; } [unitconversion(key="inch_feet")] public float inchtofeet { get; set; } }
idea unitconversion class or may custom attribute, not sure, read value , key , accordingly converts per formula in database.
my dilema not able implement in web api. trying custom attribute no luck far.
let me know if need more information. using angularjs in front end.
any advise on solution highly appreciated.
in opinion best approach create entity many different units
public class length { public float centimeters{ get; set; } public float inches { get; set; } }
do not involve source unit fields names. it's bed practice. want result in different units - source unit doesn't matter.
your main problem looking @ model have trouble separating data , want it.
then can solve conversion in 2 ways.
first can create 1 webapi action method conversion take input value , unit , use backing helper class conversion , return result. (read startegy/template method , factory patterns).
second creating service class per each (size/value) want convert , inside class create method every unit conversion. (this approach requires more code , less generic).
Comments
Post a Comment