.net bcl_.NET 4.1预览-新的基类库(BCL)扩展方法-RFC

.net bcl

.net bcl

As web programmers, we use a lot of strings to move data around the web. Often we’ll use a string to represent a date or an integer or a boolean. Basically "1" in instead of 1, or "April 1, 2009" rather than a proper ISO-8601 formatted culture-invariant date.

作为Web程序员,我们使用许多字符串在Web上移动数据。 通常,我们将使用字符串来表示日期,整数或布尔值。 基本上是“ 1”而不是1,或者是“ 2009年4月1日”,而不是正确的ISO-8601格式的文化不变日期。

While these strings are flying around via HTTP it's not a huge deal, but sometimes this loose, even sloppy, use of strings can leak into our own code. We might find ourselves leaving the data times as strings longer and longer, or not even bothering to convert them to their proper type at all. This problem is made worse by the proliferation of JSON, and schema-less/namespace-less XML (that I've often called "angle-bracket delimited files" as they're no more useful than CSVs in that point.

尽管这些字符串是通过HTTP传递的,但这并不是什么大问题,但是有时,这种松散甚至是草率的字符串使用可能会泄漏到我们自己的代码中。 我们可能会发现自己将数据时间留给字符串的时间越来越长,甚至根本不愿意将它们转换为正确的类型。 JSON和无模式/无命名空间的XML(我经常称其为“用尖括号分隔的文件”)使该问题变得更加严重,因为在那一点上它们比CSV更有用。

.NET 4.0 is pretty much locked down, but version 4.1 still has some really cool "Futures" features that are being argued about. If we don't know the type of a string, or we want to leave the string, as a string, longer than usual, what if we had an class that could be both a string and another type, essentially deferring the decision until the variable is observed. For example:

.NET 4.0几乎处于锁定状态,但4.1版仍具有一些很酷的“ Futures”功能,这些功能正在争论中。 如果我们不知道字符串的类型,或者我们想将字符串作为字符串保留,比平常更长,那么如果我们拥有一个既可以是字符串又可以是另一种类型的类,将决定推迟到观察到变量。 例如:

StringOr<int> userInput= GetUserInput("Quantity"); 
string szUserInput=userInput.StringValue; 
int intUserInput=userInput.OtherValue;

Sometimes you just don't know, or can't know.

有时您只是不知道,或者不知道。

This reminds me of a similar, but orthogonal physics concept, that of the Heisenberg Uncertainty Principle. Sometimes you know that an object is a string, and sometimes you know how long it is, but you can’t know both at the same time.

这让我想起了类似的但正交的物理概念,即海森堡不确定性原理。 有时您知道一个对象是一个字符串,有时您知道该对象有多长,但是您无法同时知道它们。

One of my favorite jokes goes:

我最喜欢的笑话之一是:

Heisenberg gets pulled over by the police. The officer asks, “Do you know how fast you were going?” Heisenberg answers, “No, but I know exactly where I am!”

海森堡被警方拦下。 警官问:“你知道你要走多快吗?” 海森堡回答:“不,但我确切地知道自己在哪里!”

This library doesn't solve THAT issue, with respect to strings, but we’ve got folks in DevDiv working on this and many other metaphysical - and physical - problems as they apply to computer science.

该库无法解决关于字符串的THAT问题,但是在DevDiv中,我们让人们正在研究此问题以及许多其他应用于计算机科学的形而上学和物理问题。

Big thanks to Eilon, who's working hard to get this pushed into the .NET 4.1 Base Class Library. Visit Eilon's blog for more details on this new library, more code, graphics and details on how Intellisense will handle this new case.

非常感谢Eilon ,他正努力将其推送到.NET 4.1基类库中。 请访问Eilon的博客,以获取有关此新库的更多详细信息,更多代码,图形以及Intellisense将如何处理此新案例的详细信息。

Hopefully, someone is working to make this important new library Open Source.

希望有人正在努力使这个重要的新库开源。

Your thoughts, Dear Reader?

您的想法,亲爱的读者?

Related Posts

相关文章

翻译自: https://www.hanselman.com/blog/net-41-preview-new-base-class-library-bcl-extension-methods-rfc

.net bcl

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值