2
Hello, I am creating a solution to generate the Fiscal SPED files where I make all the validation rules of each class soon in the construction of the same. This is necessary because for each Field, Block or Record there are specific rules. I was able to create my classes for types that already do all the validation but I’m having problems with Records, like this:
Custom types according to documentation
Namespace Tipos
Public Class Caractere
...
End Class
Public Class Numerico(Of T)
...
End Class
Public Class Registro
...
End Class
End Namespace
Representation of 1 record
Imports Sped.Tipos
Namespace Tipos.Bloco0
Public Class Registro0000
Inherits Registro
' Propriedades da classe
Public COD_VER As Numerico(Of Integer)
Public COD_FIN As Numerico(Of Integer)
Public DT_INI As Caractere
Public DT_FIN As Caractere
Public NOME As Caractere
Public CNPJ As Caractere
Public CPF As Caractere
Public UF As Caractere
Public IE As Caractere
Public COD_MUN As Numerico(Of Integer)
Public IM As Caractere
Public SUFRAMA As Caractere
Public IND_PERFIL As Caractere
Public IND_ATIV As Numerico(Of Integer)
' Construtor (aqui está o problema)
Public Sub New()
... validação das regras do registro ...
End Sub
End Class
End Namespace
I need to pass the properties to the class and validate at her initiation, so I understand I would use that being like this:
Startup of the record within block 0
Imports Sped.Tipos.Registros.Bloco0
Namespace Tipos.Blocos
Public Class Bloco0
Public registro0000 as Registro0000
... outros registros aqui
Public Sub New()
registro0000 = New Registro0000 With {
.COD_VER = 1,
.COD_FIN = 1,
.DT_INI = "20000101",
.DT_FIN = "20200101"
.NOME = "Foo"
.CNPJ = "00000000000000"
.CPF = ""
.UF = "MG"
.IE = ""
.COD_MUN = 0000000
.IM = ""
.SUFRAMA = ""
.IND_PERFIL = 1
.IND_ATIV = 1
}
... outras inicializações aqui
End Sub
End Class
End Namespace
In short, I need to be able to use the parameters I am going through using a initialization with an anonymous object inside the constructor of my record to then validate these values but, I am not able to understand how to process this and until then the With {}
only occurs after initialization... How to solve?