B
Benjamin Lukner
Hi!
I got a CE device that ships with a specific .Net dll.
Our software shall run on every device but load a special class from
that dll if it exists.
Unfortunately one of the parameters is a public enum value.
If I pass the corresponding int value I get an ArgumentException.
I was not able to cast the int value into something that's accepted.
I created a test code sample (single console module) that loads itself.
I even can load the enum into a System.Type.
If the parameter is optional I can pass Nothing w/o exception.
But I can't CType the int into the demanded enum nor pass it:
' 1. Load Assemby
' 2. Load Class1 (contains one enum and two constructors)
' 3. Step through constructors and try to instance
Imports System.Reflection
Module Module1
Sub Main()
Dim oDLL As [Assembly] = [Assembly].GetExecutingAssembly
Dim oClass As System.Type _
= oDLL.GetType(oDLL.GetName.Name + ".Class1")
Dim oType As System.Type _
= oDLL.GetType(oDLL.GetName.Name + ".Class1+Enum1")
Dim oCons() As ConstructorInfo = oClass.GetConstructors()
For Each oCon As ConstructorInfo In oCons
Dim o() As Object = New Object() {1, Nothing}
Dim oPIC As Object = oCon.Invoke(o)
oPIC = Nothing
Next
End Sub
End Module
Public Class Class1
Public Enum Enum1
Value1
Value2
End Enum
Public Sub New(ByVal Parm1 As Int32, _
Optional ByVal Parm2 As Enum1 = Enum1.Value1)
MsgBox("This works")
End Sub
Public Sub New(ByVal Parm1 As Enum1, _
Optional ByVal Parm2 As Enum1 = Enum1.Value1)
MsgBox("This ain't")
End Sub
End Class
There should be an easy solution but I couldn't find it by now.
Maybe someone can put me back on track
Regards,
Benjamin Lukner
I got a CE device that ships with a specific .Net dll.
Our software shall run on every device but load a special class from
that dll if it exists.
Unfortunately one of the parameters is a public enum value.
If I pass the corresponding int value I get an ArgumentException.
I was not able to cast the int value into something that's accepted.
I created a test code sample (single console module) that loads itself.
I even can load the enum into a System.Type.
If the parameter is optional I can pass Nothing w/o exception.
But I can't CType the int into the demanded enum nor pass it:
' 1. Load Assemby
' 2. Load Class1 (contains one enum and two constructors)
' 3. Step through constructors and try to instance
Imports System.Reflection
Module Module1
Sub Main()
Dim oDLL As [Assembly] = [Assembly].GetExecutingAssembly
Dim oClass As System.Type _
= oDLL.GetType(oDLL.GetName.Name + ".Class1")
Dim oType As System.Type _
= oDLL.GetType(oDLL.GetName.Name + ".Class1+Enum1")
Dim oCons() As ConstructorInfo = oClass.GetConstructors()
For Each oCon As ConstructorInfo In oCons
Dim o() As Object = New Object() {1, Nothing}
Dim oPIC As Object = oCon.Invoke(o)
oPIC = Nothing
Next
End Sub
End Module
Public Class Class1
Public Enum Enum1
Value1
Value2
End Enum
Public Sub New(ByVal Parm1 As Int32, _
Optional ByVal Parm2 As Enum1 = Enum1.Value1)
MsgBox("This works")
End Sub
Public Sub New(ByVal Parm1 As Enum1, _
Optional ByVal Parm2 As Enum1 = Enum1.Value1)
MsgBox("This ain't")
End Sub
End Class
There should be an easy solution but I couldn't find it by now.
Maybe someone can put me back on track
Regards,
Benjamin Lukner