You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use ToCSharpString on any TypedConstant that represents a float
Expected Behavior:
It produces a string that represents the float and could be used to initialise a new float in C#, i.e., 0.5f
Actual Behavior:
It produces a string without a type suffix, i.e., 0.5
Use case:
I'm creating a source generator that generates source code based on NamedArguments in AttributeData. When the named argument's value is retrieved, I use arg[x].Value.ToCSharpString() to turn the value into a string to place in the generated code and the string being generated for floats is causing compile errors
The text was updated successfully, but these errors were encountered:
I wouldn't expect it to match the original (like if the original expression was complex where multiple floats were added together or something), but I was expecting it to produce compilable code. Would 0.5 be considered legal C# syntax for a typed constant representing a float, as wouldn't it always be interpreted as a double?
Version Used:
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
Steps to Reproduce:
TypedConstant
that represents a floatExpected Behavior:
It produces a string that represents the float and could be used to initialise a new float in C#, i.e.,
0.5f
Actual Behavior:
It produces a string without a type suffix, i.e.,
0.5
Use case:
I'm creating a source generator that generates source code based on
NamedArguments
inAttributeData
. When the named argument's value is retrieved, I usearg[x].Value.ToCSharpString()
to turn the value into a string to place in the generated code and the string being generated for floats is causing compile errorsThe text was updated successfully, but these errors were encountered: