Units of measure in C# - almost

后端 未结 12 1277
再見小時候
再見小時候 2020-11-27 10:29

Inspired by Units of Measure in F#, and despite asserting (here) that you couldn\'t do it in C#, I had an idea the other day which I\'ve been playing around with.

         


        
12条回答
  •  执念已碎
    2020-11-27 10:59

    Thanks for the idea. I have implemented units in C# many different ways there always seems to be a catch. Now I can try one more time using the ideas discussed above. My goal is to be able to define new units based on existing ones like

    Unit lbf = 4.44822162*N;
    Unit fps = feet/sec;
    Unit hp = 550*lbf*fps
    

    and for the program to figure out the proper dimensions, scaling and symbol to use. In the end I need to build a basic algebra system that can convert things like (m/s)*(m*s)=m^2 and try to express the result based on existing units defined.

    Also a requirement must be to be able to serialize the units in a way that new units do not need to be coded, but just declared in a XML file like this:

    
      
    
    
    
    
    ...
    
    
    
    ...
      
      
    
    
    
    ...
    
      
    
    

提交回复
热议问题