Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#950 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
devtools, tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện đầu vào VB.NET trong issue và kiểm tra điểm vào của việc chuyển đổi trục thuộc tính LINQ-to-XML. So sánh lệnh gọi Attributes được tạo ra với lệnh gọi Attribute và phép ép kiểu string được mong đợi. Được coi là hoàn tất khi cả thuộc tính tồn tại và thuộc tính không tồn tại đều tạo ra các biểu thức C# mong đợi và duy trì hành vi runtime được minh họa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
C#
Star
913
Fork
244
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của icsharpcode/CodeConverter

Tất cả issue của icsharpcode/CodeConverter

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.