Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

VB -> C#: LINQ orderby and select are in wrong order

未关闭
#1,016 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
csharp
领域
devtools

调研方向

首先,使用此 issue 中显示的 LINQ 输入重现 VB-to-C# 转换,并将生成的查询与预期输出进行比较。跟踪处理 Select 和 Order By 的转换路径,然后验证生成的 C# 保留了排序顺序,并且可以在不出现报告错误的情况下编译。

由索引模型根据 Issue 内容生成。

描述

enhancement VB -> C#
VB.Net input code
Public Class ConversionTest7
    Private Class MyEntity
        Property EntityId As Integer
        Property FavoriteColorId As Integer
        Property Name As String
    End Class
    Private Class MyColor
        Property ColorId As Integer
        Property Color As String
    End Class
    Public Sub BugRepro()

        Dim entities As New List(Of MyEntity)
        Dim colors As New List(Of MyColor)

        Dim wrongOrder = (From e In entities
                          Join c In colors On c.ColorId Equals e.FavoriteColorId
                          Where e.FavoriteColorId > 0 And c.Color = "green"
                          Select e, c
                          Order By e.Name).ToList
    End Sub
End Class
Erroneous output
public class ConversionTest7
    {
        private class MyEntity
        {
            public int EntityId { get; set; }
            public int FavoriteColorId { get; set; }
            public string Name { get; set; }
        }
        private class MyColor
        {
            public int ColorId { get; set; }
            public string Color { get; set; }
        }
        public void BugRepro()
        {

            var entities = new List<MyEntity>();
            var colors = new List<MyColor>();

            var wrongOrder = (from e in
                                  from e in entities
                                  join c in colors on e.FavoriteColorId equals c.ColorId
                                  where e.FavoriteColorId > 0 & c.Color == "green"
                                  select new { e, c }
                              orderby e.Name
                              select e).ToList();
        }
    }
Expected output

var wrongOrder = (from e in entities
                              join c in colors on e.FavoriteColorId equals c.ColorId
                              where e.FavoriteColorId > 0 & c.Color == "green"
                              orderby e.Name
                              select new { e, c }).ToList();

Details
  • Product in use: VS extension
  • Version in use: 9.2.2.0
  • Even though it's bad practice, Visual Studio allows the OrderBy to be after the Select when writing VB.NET. But after converting to C#, VS shows an error with the code. The converter should swap the OrderBy and Select statements in this example to prevent the error.
  • The converted code above also illustrates issue #931 but I think it's a separate problem.
主要语言
C#
星标
914
派生
242
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

icsharpcode/CodeConverter 的其他 Issue

查看 icsharpcode/CodeConverter 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。