Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Gain access to a property with reflection
Message
From
06/02/2013 03:29:56
 
 
To
05/02/2013 09:44:43
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01565141
Message ID:
01565241
Views:
56
>I have adjusted for this. If someone has a better approach, you may let me know.
>
>
>    ' Non visual operations that do specific tasks and redirect to a specific page
>    Public Function Operation() As Boolean
>        Dim lcMessage As String = ""
>        Dim lnOperation As Integer = 1
>        Dim loOperation As Operation = New Operation(oProcess)
>        Dim loOperationMethodInfo As System.Reflection.MethodInfo = Nothing
>        Dim loOperationType As Type = loOperation.GetType()
>        Dim loOperationParameter(0) As Object
>        Dim loPropertyInfo As System.Reflection.PropertyInfo = Nothing
>
>        ' Get the operation ID
>        lnOperation = Val(oProcess.GetProcess("Operation"))
>
>        ' Define the parameter
>        loOperationParameter(0) = False
>
>        ' Use reflection to dynamically access the method
>        loOperationMethodInfo = loOperationType.GetMethod("Operation" + lnOperation.ToString)
>
>        ' Call the method
>        If Not loOperationMethodInfo.Invoke(loOperation, loOperationParameter) Then
>            loPropertyInfo = loOperationType.GetProperty("cMessage")
>            lcMessage = CType(loPropertyInfo.GetValue(loOperationMethodInfo, Nothing), String)
>            Throw New System.Exception(lcMessage)
>        End If
>
>        Return True
>    End Function
>
Looks OK as long as you're sure GetMethod() won't return null.

Hard to get a clear picture without knowing what the external references are:
What's Operation ?
What's oProcess ?

If it was C# then using dynamic might be better - but, IIRC, VB.NET has some limitations in that respect :-}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform