VB -> C#: The LINQ-to-XML attribute axis accessor should be translated as a call to XElement.Attribute rather than XElement.Attributes.
还没有人认领这个 Issue。
评估
调研方向
首先重现 issue 中的 VB.NET 输入,并检查 LINQ-to-XML 属性轴转换的入口点。将生成的 Attributes 调用与预期的 Attribute 调用和 string 强制转换进行比较。完成的标准是,现有属性和缺失属性都生成预期的 C# 表达式,并保留所示的运行时行为。
由索引模型根据 Issue 内容生成。
描述
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.@AttributeNamereturns 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
icsharpcode/CodeConverter 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
icsharpcode/CodeConverter#1271 · 1 条评论 ·
-
C# -> VB
难度 4/5 3-5 天 新手友好度 35/100
icsharpcode/CodeConverter#1281 ·
-
难度 3/5 1-2 天 新手友好度 55/100
icsharpcode/CodeConverter#1275 ·
-
VB -> C#
难度 3/5 1-2 天 新手友好度 62/100
icsharpcode/CodeConverter#1273 ·
-
VB -> C#: "Group By Into" Linq queries supressing aggregations ("Into" part) in the converted code 未关闭Difficult area VB -> C#
难度 3/5 1-2 天 新手友好度 74/100
icsharpcode/CodeConverter#1272 ·
查看 icsharpcode/CodeConverter 的全部 Issue
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
-
Type: enhancement
难度 2/5 1-3 小时 新手友好度 65/100
apache/arrow-adbc#4809 ·
-
type/automation type/tech-debt
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 65/100
microsoft/vscode-azurefunctions#5197 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 85/100
microsoft/microsoft-ui-reactor#1274 ·