I am trying to do some data ingestion from different data files (Excel) with two known formats (represented by Classes D1
and D2
, derived from Class B
which contains common elements). I have to create many sets of D1
and D2
instances before doing the final data set assembly, and each set is created through a typed Class ExemplarIssue
.
Is there a way to create an instance of my data elements (D1
, D2
) using parameters without getting the BC32085
error? My minimal example is included here, the detail I provide below is to provide some context in how I got here.
Public Class ExemplarIssue(Of T As {B, New})
Public Sub New()
End Sub
Public Sub Test1()
Dim x As New T
Dim y As New T("1", "2") 'Error BC32085 Arguments cannot be passed To a 'New' used on a type parameter.
Dim z As New Collections.Generic.List(Of T)
z.Add(y)
End Sub
End Class
Public MustInherit Class B
Public Sub New()
End Sub
Public Sub New(s1 As String, s2 As String)
End Sub
End Class
Public Class D1
Inherits B
Public Sub New()
MyBase.New()
End Sub
Public Sub New(s1 As String, s2 As String)
MyBase.New(s1, s2)
End Sub
End Class
Public Class D2
Inherits B
Public Sub New()
MyBase.New()
End Sub
Public Sub New(s1 As String, s2 As String)
MyBase.New(s1, s2)
End Sub
End Class
The work involves passing formatted data (s2
in well-understood formats) which is ingested by the Class into useable properties. There is a whole bunch of data checks that happen within the encapsulated class.
I am trying to make the ingested data immutable (i.e. only expose read-only properties). As such, I would like to constrain use of the date element Classes so that creating one does not make any sense without the data to be stored. This is usually done with a parameterised New(...)
routine, and not including the unparameterised New()
routine.
I am trying to keep my code DRY - not make a similar ExemplarIssue
Class for each Dx
. And in order to find and process each file I have created a class that runs a routine (Test1
in this case). I am using a Class because there will be many of these mini data sets that I must process later to create a master clean data set. The custom typed class allows me to add additional checks and functions that I could not get just by using a generic collection. These additional functions includes having a data ingest error log, hence why it is encapsulated in a class rather than as a function in a main module.