alina_moise24
New Member
I am trying to dynamically call a method, an alternative to InvokeMethod which can be too slow.
Do you have any suggestion on how can I do this?
When I run the below code I get following exception: Type must derive from Delegate.
Any idea how can I get the delegate type?
CLASS Dict:
DEFINE PROTECTED VARIABLE iObjArray AS System.Array NO-UNDO.
DEFINE PROTECTED VARIABLE iType AS System.Type NO-UNDO.
DEFINE PROTECTED VARIABLE iDict AS System.Object NO-UNDO.
DEFINE PROTECTED VARIABLE iMethodInfo AS System.Reflection.MethodInfo NO-UNDO.
DEFINE PROTECTED VARIABLE iDelType AS System.Type NO-UNDO.
DEFINE PROTECTED VARIABLE iDelegate AS System.Delegate NO-UNDO.
CONSTRUCTOR Dict() :
iType = TypeHelper:GetType("System.Collections.Generic.Dictionary`2[System.String,System.Object]").
iDict = Activator:CreateInstance(iType).
iObjArray = System.Array:CreateInstance(TypeHelper:GetType("System.Object"), 1).
END CONSTRUCTOR.
METHOD PUBLIC System.Object GetValue(INPUT chKey AS CHARACTER):
iObjArray:SetValue(chKey, 0).
/*RETURN inoType:InvokeMember("Item", BindingFlags:GetProperty, ?, iDict, iObjArray).*/
iMethodInfo = iType:GetMethod("Item", BindingFlags:GetProperty).
iDelType = iMethodInfo:GetType().
iDelegate = System.Delegate:CreateDelegate(iDelType, iDict, iMethodInfo).
RETURN iDelegate
ynamicInvoke(iObjArray).
END METHOD.
DESTRUCTOR PUBLIC Dict() :
DELETE OBJECT iObjArray.
END DESTRUCTOR.
END CLASS.
Does anyone know how can I create an object using reflections and make it fast?
Thanks in advance
Do you have any suggestion on how can I do this?
When I run the below code I get following exception: Type must derive from Delegate.
Any idea how can I get the delegate type?
CLASS Dict:
DEFINE PROTECTED VARIABLE iObjArray AS System.Array NO-UNDO.
DEFINE PROTECTED VARIABLE iType AS System.Type NO-UNDO.
DEFINE PROTECTED VARIABLE iDict AS System.Object NO-UNDO.
DEFINE PROTECTED VARIABLE iMethodInfo AS System.Reflection.MethodInfo NO-UNDO.
DEFINE PROTECTED VARIABLE iDelType AS System.Type NO-UNDO.
DEFINE PROTECTED VARIABLE iDelegate AS System.Delegate NO-UNDO.
CONSTRUCTOR Dict() :
iType = TypeHelper:GetType("System.Collections.Generic.Dictionary`2[System.String,System.Object]").
iDict = Activator:CreateInstance(iType).
iObjArray = System.Array:CreateInstance(TypeHelper:GetType("System.Object"), 1).
END CONSTRUCTOR.
METHOD PUBLIC System.Object GetValue(INPUT chKey AS CHARACTER):
iObjArray:SetValue(chKey, 0).
/*RETURN inoType:InvokeMember("Item", BindingFlags:GetProperty, ?, iDict, iObjArray).*/
iMethodInfo = iType:GetMethod("Item", BindingFlags:GetProperty).
iDelType = iMethodInfo:GetType().
iDelegate = System.Delegate:CreateDelegate(iDelType, iDict, iMethodInfo).
RETURN iDelegate

END METHOD.
DESTRUCTOR PUBLIC Dict() :
DELETE OBJECT iObjArray.
END DESTRUCTOR.
END CLASS.
Does anyone know how can I create an object using reflections and make it fast?
Thanks in advance