linq - C# Visitor pattern Expressions to build result Unit of measure -


i embarking on project involving calculations , have started straightforward uom (unit of measurement) adaptation based on cureos framework. far good, i've got basic units represented.

one of things build upon foundational units in order arrive @ calculated values. instance, if have length (or distance) , time, can arrive @ velocity (distance / time) or acceleration (distance / square(time)).

my units flexible; can show them either english, si, or whatever system happens in whatever quantity need, whether feet, inches, meters, centimeters, etc. or in case of time, milliseconds, seconds, minutes, etc.

what i'd report actual unit @ moment of calculation. if units meters , seconds, i'd report "m/s" velocity or "m/s^2" acceleration. or, if units feet , milliseconds, report "ft/ms" or "ft/ms^2", respectively.

so... story backdrop, entertaining possibility of expressing these more complex units (if will, maybe it's unit, maybe it's not... that's tbd) linq expression trees whereby plausibly visit nodes throughout expression tree units , "compile" unit names in addition actual numeric result.

if objects involved measures (for quantifiable values), units (for units) , quantities (for kind of unit), seems me should quite doable.

thoughts?

i'm not sure you're asking here, when confronted problem of maintaining units of different variables in program , finding correct units of resultant value, solution came with.

using system;  namespace consoleapplication1 {     public interface mass     {     }      public class kg: mass     {     }      public interface length     {     }      public interface m : length     {     }      public interface m<in t>: m t: m, length     {     }      public interface time     {     }      public interface s : time     {     }      public interface s<in t> : s t : s, time     {     }      public interface iunit<in m, in l, in t>          m: mass          l: length         t: time     {     }      public sealed class unit<m, l, t>: iunit<m, l, t>         m : mass         l : length         t : time     {         public static unit<m, l, t>  operator +(unit<m, l, t> a, unit<m, l, t> b)         {             throw new notimplementedexception();         }     }      public interface nil: mass, length, time     {     }      class program     {         static void main(string[] args)         {             unit<nil, m, s<s>> value1 = null;             unit<nil, m, s<s>> value2 = null;              var result = value1 + value2;         }     } } 

this allow define operators on units return other units (simple mlt math). note s s^2 , readable way came implement feature.

hope helps!


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -