views:

70

answers:

1

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?

+2  A: 

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

Femaref
In my CsToken I have CsTokenType and CsTokenClass. Both are showing "Number" which of course is still the issue. Unless I'm using it the wrong way
PSU_Kardi
e.g. double x = 0.15; About what are we talking here? the "double" part, or the 0.15?
Femaref
The way the token works is it goes CSToken token;token.Text = 0.15;token.CsTokenType = Number;token.CsTokenClass = Number;
PSU_Kardi