VB -> C#: Nullable comparisons in While conditions produce invalid C#
Mantenedores costumam responder em até 3 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 68/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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).
- Linguagem predominante
- C#
- Estrelas
- 917
- Forks
- 243
- Merge médio
- 2d 15h
- PRs com merge (30d)
- 9
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de icsharpcode/CodeConverter
-
VB -> C#
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
icsharpcode/CodeConverter#1301 ·
Mantenedores costumam responder em até 3 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
icsharpcode/CodeConverter#1271 · 1 comentário ·
Mantenedores costumam responder em até 3 dias
-
VB -> C#: Generic extension method inference widens element types when using a base-type comparerAbertaVB -> C#
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
icsharpcode/CodeConverter#1302 ·
Mantenedores costumam responder em até 3 dias
-
VB -> C#
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
icsharpcode/CodeConverter#1299 ·
Mantenedores costumam responder em até 3 dias
-
VB -> C#
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 62/100
icsharpcode/CodeConverter#1298 ·
Mantenedores costumam responder em até 3 dias
Todas as issues de icsharpcode/CodeConverter
Issues semelhantes
-
needs-area-label
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
Mantenedores costumam responder em até 1 dia
-
bug github_actions
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
endercodezz/BYDLO#336 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
SubtitleEdit/subtitleedit#16638 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100