I have a Partial Class
in a file MainFile.vb
with a constructor like this:
Partial Class MyAwesomeClass
' The constructor - Name it MainConstructor
Public Sub New(Dim x As Integer)
' Some awesome code here
Line1_of_code()
Line2_of_code()
Line3_of_code()
End Sub
End Class
Now I want to add some more lines of code in the same constructor i.e. MainConstructor
but my problem(s) is/are:
- I can't edit the file
MainFile.vb
- I can't create another constructor
- All I can do is -- since the
MyAwesomeClass
is aPartial Class
; I can create another file e.g.ExtendedFile.vb
and write my lines of code
So I'm trying to do like this which is not allowed in .NET
:
Partial Class MyAwesomeClass
' The extended constructor - Name it ExtConstructor
Public Sub New(Dim x As Integer) ' Boom!!!! Error: Duplicate constructor with same kind of arguments
' my extended awesome code here
Line4_of_code()
Line5_of_code()
Line6_of_code()
End Sub
End Class
Ultimately I want to do something like - When I create an object
of MyAwesomeClass
; it should execute Line1_of_code()
to Line6_of_code()
. I.e.
Dim objAwesome As New MyAwesomeClass(5) ' Any Integer will do
should execute all the below lines for objAwesome
(and in the same order, too)
Line1_of_code()
Line2_of_code()
Line3_of_code()
Line4_of_code()
Line5_of_code()
Line6_of_code()
I'm using .NET Fx 4.0 -- Is there any workaround or solution? Any help would be appreciated.