Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
MarshalAs for Properties in a struct

I am trying to add getters and setters to this struct, so I can use it as a listView items source. The problem is, this causes MarshalAs to be invalid thus not allowing compilation. What would the best option be to fix this?

Attribute 'MarshalAs' is not valid on this declaration type. It is only valid on 'field, parameter, return' declarations.**

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct FileExplorerData
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 251)]
        public string name { get; set; }
        public FILETIME lastwrite { get; set; }
        public bool type { get; set; }
        public int size { get; set; }
    };
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can specify the underlying field as the target of the attribute

[field: MarshalAs(UnmanagedType.ByValTStr, SizeConst = 251)]
public string name { get; set; }

This is valid from C# 7.3+. See the documentation.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda