Stylecop - 确定是 Double 还是 Float

发布于 2024-08-26 18:12:08 字数 191 浏览 15 评论 0原文

我正在使用 Stylecop 制定一些自定义规则,并尝试确定我是否有双精度型或浮点数。

我能够遍历该语句并获得 CSTokenType。 CSTokenType 是数字,可以作为字符串读取。但由于它只是一个数字,我没有真正的方法知道它是 int、float、long、double 还是其他类型。

关于如何检查原始类型是什么的任何想法?

I'm using Stylecop to come up with some custom rules and I'm trying to determine if I have a double or a float.

I'm able to walk through the statement and get a CSTokenType. The CSTokenType is number and can be read as a string. But since it's just a Number I have no real way of knowing if it's an int, float , long , double or whatever.

Any ides on how I can check to see what the primitive type is?

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

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

发布评论

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

评论(1

心凉怎暖 2024-09-02 18:12:08

编辑

要确定数字文字是双精度型还是浮点数,您必须检查 CsToken.Text 中是否存在以及如果是,哪个后缀(当 CsTokenType == CsTokenType.Number 时)。

一些示例:

  • 15 是整数
  • 0.15 是双精度型
  • 0.15d 是双精度型
  • 0.15f 是浮点数
  • 0.15m 是小数

来源: http://msdn.microsoft.com/en-us/library/aa691085(v=VS.71).aspxhttp://msdn.microsoft.com/en-us /library/aa664674(v=VS.71).aspx

EDIT

To decide whether a number literal is a double or float, you have to check if and if yes, which suffix is present in CsToken.Text (when CsTokenType == CsTokenType.Number).

Some examples:

  • 15 is an integer
  • 0.15 is a double
  • 0.15d is a double
  • 0.15f is a float
  • 0.15m is a decimal

source: http://msdn.microsoft.com/en-us/library/aa691085(v=VS.71).aspx and http://msdn.microsoft.com/en-us/library/aa664674(v=VS.71).aspx

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