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

VB -> C#: The LINQ-to-XML attribute axis accessor should be translated as a call to XElement.Attribute rather than XElement.Attributes.

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

还没有人认领这个 Issue。

评估

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

调研方向

首先重现 issue 中的 VB.NET 输入,并检查 LINQ-to-XML 属性轴转换的入口点。将生成的 Attributes 调用与预期的 Attribute 调用和 string 强制转换进行比较。完成的标准是,现有属性和缺失属性都生成预期的 C# 表达式,并保留所示的运行时行为。

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

描述

Good for coding agent VB -> C#
VB.Net input code
    Dim x = <MyTag MyAttribute="a"/>

    Dim existingAttributeValue As String = x.@MyAttribute
    Dim missingAttributeValue As String = x.@MissingAttribute

    Console.WriteLine(existingAttributeValue = "a")
    Console.WriteLine(missingAttributeValue Is Nothing)
Erroneous output

(snipped to the relevant part)

    string existingAttributeValue = x.Attributes("MyAttribute");
    string missingAttributeValue = x.Attributes("MissingAttribute");
Expected output
    string existingAttributeValue = (string)x.Attribute("MyAttribute");
    string missingAttributeValue = (string)x.Attribute("MissingAttribute");
Details
  • Product in use: icsharpcode.github.io/CodeConverter [NB: Here's a typo in the github issue template] / VS extension 9.0.4.0
  • VB.NET's x.@AttributeName returns a string, and so should the converted C# expression. Casting the result to string (using the explicit conversion defined in XAttribute) seems to be the idiomatic way in C# to get this value. In addition, that's also what the VB compiler does (indirectly, via a call to My.InternalXmlHelper). Multiple matching attributes (which would be an argument for calling Attributes) are not an issue, since attribute names must be unique within an XElement, and the documentation of XElement.Attributes(XName) explicitly states that the returned collection always contains exactly 0 or 1 elements.
主要语言
C#
星标
913
派生
244
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 摘要。