VB -> C#: Nullable comparisons in While conditions produce invalid C#
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with the VB input and expected C# output in the issue, then trace how the converter handles While conditions and nullable comparisons. Add a regression test for the supplied case, including the parenthesized comparison variant. Done means the generated condition is a non-nullable bool and preserves VB's behavior when either value is Nothing.
由索引模型根据 Issue 内容生成。
描述
VB.Net input code
Imports System
Class TestClass
Sub TestMethod(startDate As Date?, endDate As Date?)
Dim currentDate = startDate
While currentDate <= endDate
currentDate = currentDate.Value.AddMinutes(1)
End While
End Sub
End Class
Erroneous output
The converted while condition evaluates to bool? rather than bool, producing:
CS0266: Cannot implicitly convert type 'bool?' to 'bool'.
An explicit conversion exists (are you missing a cast?)
Expected output
using System;
internal partial class TestClass
{
public void TestMethod(DateTime? startDate, DateTime? endDate)
{
var currentDate = startDate;
while (currentDate.HasValue && endDate.HasValue && currentDate.Value <= endDate.Value)
currentDate = currentDate.Value.AddMinutes(1d);
}
}
Details
- Product in use: VS extension, built locally from master.
- Version in use: 10.0.1, local development build.
- Did you see it working in a previous version, which? No.
- VB permits nullable comparisons in
Whileconditions. If the condition evaluates toNothing, the loop body is not executed. C# requires a non-nullableboolcondition. - The converter does not recognize
Whileas a context requiring a non-nullable Boolean result, so it preserves the comparison's nullable result instead of treatingNothingas false. - The issue also occurs when the comparison is enclosed in parentheses:
While (currentDate <= endDate).
- 主要语言
- C#
- 星标
- 917
- 派生
- 243
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 9
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
icsharpcode/CodeConverter 的其他 Issue
-
VB -> C#
难度 2/5 1-3 小时 新手友好度 72/100
icsharpcode/CodeConverter#1301 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
icsharpcode/CodeConverter#1271 · 1 条评论 ·
维护者通常 3 天内回复
-
VB -> C#: Generic extension method inference widens element types when using a base-type comparer未关闭VB -> C#
难度 4/5 3-5 天 新手友好度 55/100
icsharpcode/CodeConverter#1302 ·
维护者通常 3 天内回复
-
VB -> C#
难度 3/5 1-2 天 新手友好度 62/100
icsharpcode/CodeConverter#1299 ·
维护者通常 3 天内回复
-
VB -> C#
难度 3/5 1-2 天 新手友好度 62/100
icsharpcode/CodeConverter#1298 ·
维护者通常 3 天内回复
查看 icsharpcode/CodeConverter 的全部 Issue
相似的 Issue
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复
-
bug github_actions
难度 2/5 1-3 小时 新手友好度 78/100
endercodezz/BYDLO#336 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
SubtitleEdit/subtitleedit#16638 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 85/100
sebastienros/jint#4449 ·
维护者通常 1 天内回复