kevp75
asked on
CallByName Help? - Part Duh...
Is there a way I can use CallByName to call a private property residing inside a method?
For instance... the following code allows me to assign Namespace.Class.Method, or Namespace.Class.Property, or string
Now what I am finding is that if the property/method is not public, i get nothing in return
Private methods...fine, I can deal with that.... but there are a few instances where I need the private properties that reside inside a public method.
For instance... the following code allows me to assign Namespace.Class.Method, or Namespace.Class.Property, or string
Now what I am finding is that if the property/method is not public, i get nothing in return
Private methods...fine, I can deal with that.... but there are a few instances where I need the private properties that reside inside a public method.
Private Function Invoker(ByVal MethodName As String, Optional ByVal NamespaceName As String = Nothing, Optional ByVal ClassName As String = Nothing, Optional ByVal PropertyName As String = Nothing, Optional ByVal StringValue As String = Nothing, Optional ByVal Params() As Object = Nothing) As String
If (Len(PropertyName) > 0) Then
If (Len(ClassName) > 0) Then
If Not (Len(NamespaceName) > 0) Then
_IT = Type.GetType(ClassName, True, True)
Else
_IT = Type.GetType(NamespaceName & "." & ClassName, True, True)
End If
Else
_IT = Type.GetType(Me.ToString, True, True)
End If
Return CallByName(Activator.CreateInstance(_IT), PropertyName, CallType.Get)
ElseIf Len(StringValue) > 0 Then
Return StringValue
Else
If (Len(ClassName) > 0) Then
If Not (Len(NamespaceName) > 0) Then
_IT = Type.GetType(ClassName, True, True)
Else
_IT = Type.GetType(NamespaceName & "." & ClassName, True, True)
End If
Else
_IT = Type.GetType(Me.ToString, True, True)
End If
If IsNothing(Params) Then
Return CallByName(Activator.CreateInstance(_IT), MethodName, CallType.Get)
Else
Return CallByName(Activator.CreateInstance(_IT), MethodName, CallType.Method, Params)
End If
End If
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CallByName was included for backward compatibility with VB6, and may be a simplified wrapper for Reflection, but it appears to be too limited. The MethodInfo class has the Invoke method to execute the method.
ASKER
I will have to mess around with what you posted above and make it do what I need, so it may take some time to get back to you on whether I can get it to work with how I need it to work. :)
Will that allow me to fire the properties/methods off, or is this just gathering information?