How to get all the public properties of a class in the order they were declared in VB.NET

0

I am creating a library to validate the Fiscal SPED in VB.NET and to speed up the process of creating the lines, each class already has its predefined attributes and in the order according to the documentation, as in the example below: p>

' REGISTRO 0001: ABERTURA DO BLOCO 0
Public Class Registro0001

    ' Texto fixo contendo “0001”. 
    Public Shared reg As String = "0001"

    ' Indicador de movimento:
    '   0- Bloco com dados informados;
    '   1- Bloco sem dados informados.
    Public indMov As String = ""

    ' construtor
    Public Sub New(_reg As String, _indMov As String)
        reg = _reg
        indMov = _indMov
    End Sub

    Public Overrides Function ToString() As String
        Return $"|{reg}|{indMov}|"
    End Function

End Class

Is there any way I can get all the properties that exist within the class in the order they were declared and use the content instantiated in them within my ToString() ? method

I was thinking of something it > but I can not understand how.

    
asked by anonymous 23.01.2018 / 13:40

1 answer

1

Nothing warrants order, so you can not do this.

If you want a lot, you can use an attribute by setting the order manually and picking up that value on each property to use as the sort key.

Actually almost always when you start doing this C # is not the proper language for the problem. Although I think it is, but done differently. So much that I do not see any agility in this, on the contrary, the performance will suffer.

You need to learn to undergo reflection and attributes:

23.01.2018 / 15:44