C# 访问者模式 构建结果的表达式 度量单位
我正在着手一个涉及一些计算的项目,并从基于 Cureos 框架的相当简单的 UOM(测量单位)改编开始。到目前为止一切顺利,我已经有了一些基本的单位。
我想做的一件事是建立在基本单位的基础上,以获得计算值。例如,如果我们有长度(或距离)和时间,我们可以得出速度(距离/时间)或加速度(距离/平方(时间))。
我的单位很灵活;我可以将它们显示为英制、国际单位制或系统中我需要的任何数量,无论是英尺、英寸、米、厘米等。或者以时间、毫秒、秒、分钟等形式显示
。我想做的是报告计算时的实际单位。因此,如果单位是米和秒,我想报告速度为“m/s”或加速度为“m/s^2”。或者,如果单位是英尺和毫秒,则分别报告“ft/ms”或“ft/ms^2”。
所以...以这个故事为背景,我很高兴将这些更复杂的单元表达为 Linq 表达式树
如果涉及的对象是度量(对于可量化的值)、单位(对于单位)和数量(对于单位的种类),在我看来这应该是完全可行的。
想法?
I am embarking on a project involving some calculations and have started with a fairly straightforward UOM (Unit of Measurement) adaptation based on the Cureos framework. So far so good, I've got some basic Units represented.
One of the things I would like to do is to build upon the foundational units in order to arrive at calculated values. For instance, if we have Length (or Distance) and Time, we can arrive at Velocity (Distance / Time) or Acceleration (Distance / Square(Time)).
My units are flexible; I can show them as either English, SI, or whatever the system happens to be in whatever quantity I need, whether feet, inches, meters, centimeters, etc. Or in the case of time, milliseconds, seconds, minutes, etc.
What I'd like to do is report the actual unit at the moment of calculation. So if the units are meters and seconds, I'd like to report "m/s" for Velocity or "m/s^2" for Acceleration. Or, if the units are feet and milliseconds, report "ft/ms" or "ft/ms^2", respectively.
So... With that story as the backdrop, I am entertaining the possibility of expressing these more complex units (if you will, maybe it's a unit, maybe it's not... that's TBD) as Linq Expression Trees whereby I could plausibly visit the nodes throughout the Expression Tree for its units and "compile" the unit names just in addition to the actual numeric result.
If the objects involved are Measures (for quantifiable values), Units (for the units) and Quantities (for the kind of unit), it seems to me this should be quite doable.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您在这里要求什么,但是当遇到在程序中维护不同变量的单位并找到结果值的正确单位的问题时,这就是我想出的解决方案。
这将允许您在返回其他单位的单位上定义运算符(简单的 MLT 数学)。请注意,S 实际上是 S^2,并且是我想出的实现此功能的最易读的方法。
希望这有帮助!
I'm not sure what you're asking for here, but when confronted with the problem of maintaining units of different variables in my program and finding the correct units of the resultant value, this is the solution I came up with.
This would allow you to define operators on units which return other units (simple MLT math). Note that the S is actually S^2 and is the most readable way I came up with to implement this feature.
Hope this helps!