有谁知道用于处理数量/计量单位对的库?

发布于 2024-07-05 03:46:50 字数 300 浏览 8 评论 0原文

我希望能够做这样的事情,

var m1 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Pounds);
var m2 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Liters);

m1.ToKilograms();
m2.ToPounds(new Density(7.0, DensityType.PoundsPerGallon);

如果还没有这样的事情,有人有兴趣将其作为操作系统项目吗?

I would like to be able to do such things as

var m1 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Pounds);
var m2 = new UnitOfMeasureQuantityPair(123.00, UnitOfMeasure.Liters);

m1.ToKilograms();
m2.ToPounds(new Density(7.0, DensityType.PoundsPerGallon);

If there isn't something like this already, anybody interested in doing it as an os project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

无人接听 2024-07-12 03:46:50

有一篇关于 CodeProject 的(旧)文章。 我之前在生产环境中使用过它并且效果很好。 我们遇到了一些小问题(性能等),我已经解决了。 我将所有这些内容放在一个库中,您可以在此处找到。

免责声明:我是这个项目的维护者,所以这可能会被认为是一个无耻的插件。 然而,图书馆是免费的(就像啤酒和演讲一样)。

它包括 SI 单位,但也允许创建新单位和转换。

例如,您可以创建一个单位“XP”(经验点)。 然后你可以注册一个到“m”的转换(米,没有意义,但你可以做到)。 您还可以创建诸如 3 XP/分钟(每分钟 3 经验点)的金额。 我相信它提供了不错的默认值,同时允许灵活性。

There is an (old) article on CodeProject. I've used it in a production environment previously and it worked great. We had some minor issues (performance amongst others), which I addressed. I put all this in a library you can find here.

Disclaimer: I am the maintainer of this project, so this might be conceived as a shameless plug. The library is free (as in beer and as in speech) however.

It includes the SI units, but also allows creating new units and conversions.

So you can for example create a unit "XP" (experience points). You can then register a conversion to "m" (meter, makes no sense, but you can do it). You can also create an amount like 3 XP/min (3 experience points per minute). I believe it offers decent defaults, while allowing flexibility.

相对绾红妆 2024-07-12 03:46:50

Unix units 恕我直言,非常棒; 来源必须在网络上的某个地方。
(在“错误”下,原始文档说“不要将您的财务计划建立在货币兑换的基础上”。)

Unix units is imho brilliant; source must be on the web somewhere.
(Under "bugs", the original doc said "do not base your financial plans on the currency conversions".)

ぶ宁プ宁ぶ 2024-07-12 03:46:50

查看代码项目上的测量单位转换库

Check out the Measurement Unit Conversion Library on The Code Project.

烟雨凡馨 2024-07-12 03:46:50

实际上,我们在我工作的地方建造了一个内部设施。 不幸的是,它不向公众开放。

这实际上是一个很棒的项目,而且做起来并不难。 如果您打算自己做某事,我建议您阅读数量维度单位基本单位)。

这些帮助我们清楚地理解问题的领域,并对库的设计有很大帮助。

We actually built one in-house where I work. Unfortunately, it's not available for the public.

This is actually a great project to work on and it's not that hard to do. If you plan on doing something by yourself, I suggest you read about Quantity, Dimension and Unit (fundamental units).

These helped us understand the domain of the problem clearly and helped a lot in designing the library.

帅气称霸 2024-07-12 03:46:50

第 10 章. 数量原型模式中该书 企业模式和 MDA :使用原型模式和 UML 构建更好的软件 作者:Jim Arlow 和 Ila Neustadt
关于这个主题有一个非常有用的讨论,以及一些您可以用作指南的通用模式。

In Chapter 10. Quantity archetype pattern of the book Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML by Jim Arlow and Ila Neustadt
there is a really useful discussion of this topic and some general patterns you could use as a guide.

梦一生花开无言 2024-07-12 03:46:50

另请参阅最新的 F# 版本 - 它具有静态测量域/维度分析。

Also see the most recent F# release - it has static measurement domain/dimension analysis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文