Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#950 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
45/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
csharp
Domínio
devtools, tooling

Direção de pesquisa

Comece reproduzindo a entrada VB.NET da issue e inspecione o ponto de entrada da tradução do eixo de atributos do LINQ-to-XML. Compare a chamada Attributes gerada com a chamada Attribute esperada e o cast para string. Está concluído quando tanto os atributos existentes quanto os ausentes produzirem as expressões C# esperadas e preservarem o comportamento em tempo de execução mostrado.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.
Linguagem predominante
C#
Estrelas
914
Forks
242
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de icsharpcode/CodeConverter

Todas as issues de icsharpcode/CodeConverter

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.