dotnet/roslyn

ToCSharpString outputs floats without a type suffix

Open

#76,061 创建于 2024年11月24日

在 GitHub 查看
 (4 评论) (1 反应) (0 负责人)C# (4,257 fork)batch import
Area-Compilershelp wanted

仓库指标

Star
 (20,414 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

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:

  1. 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

贡献者指南