S
Søren M. Olesen
Hi
How do I create an instance of an object with an inherited cunstructor??
In the below example, I'm able to create an instance of MyClass2 using the
forst two lines of code, however if I try using the next two lines of code
it fails.
How do I create an instance of an object with an inherited cunstructor that
takes an argument??
TIA
Søren
Imports System.Reflection
Module Module1
Public Class MyBaseClass
Public Sub New()
End Sub
Public Sub New(ByVal arg As Boolean)
End Sub
End Class
Public Class MyClass2
Inherits MyBaseClass
End Class
Sub Main()
Dim conInfo As ConstructorInfo = GetType(MyClass2).GetConstructor(New Type()
{})
Dim myObj As Object = conInfo.Invoke(New Object() {})
Dim conInfo1 As ConstructorInfo = GetType(MyClass2).GetConstructor(New
Type() {GetType(Boolean)})
Dim myObj1 As Object = conInfo.Invoke(New Object() {False})
End Sub
End Module
How do I create an instance of an object with an inherited cunstructor??
In the below example, I'm able to create an instance of MyClass2 using the
forst two lines of code, however if I try using the next two lines of code
it fails.
How do I create an instance of an object with an inherited cunstructor that
takes an argument??
TIA
Søren
Imports System.Reflection
Module Module1
Public Class MyBaseClass
Public Sub New()
End Sub
Public Sub New(ByVal arg As Boolean)
End Sub
End Class
Public Class MyClass2
Inherits MyBaseClass
End Class
Sub Main()
Dim conInfo As ConstructorInfo = GetType(MyClass2).GetConstructor(New Type()
{})
Dim myObj As Object = conInfo.Invoke(New Object() {})
Dim conInfo1 As ConstructorInfo = GetType(MyClass2).GetConstructor(New
Type() {GetType(Boolean)})
Dim myObj1 As Object = conInfo.Invoke(New Object() {False})
End Sub
End Module