W
WinningJr
Guest
Reflection is my friend!! Working example below. Mike - I had to debug to get ReflectionHelper.cls when using methods with parameters.. You are adding objects to the paremeterTypes array and Types to the object Array: oParameterTypes:SetValue (poParameter1, 0) . oParameters:SetValue (Progress.Util.TypeHelper:GetType (pcParameterType1), 0) . For the archive, here is a working example against the Couchbase sample DB with some code stolen from Mike: DEFINE VARIABLE oObjectType AS System.Type NO-UNDO . DEFINE VARIABLE oMethodInfo AS System.Reflection.MethodInfo NO-UNDO . DEFINE VARIABLE oGenericMethod AS System.Reflection.MethodInfo NO-UNDO . DEFINE VARIABLE oObjectTypeOfArray AS "System.Type[]" NO-UNDO . DEFINE VARIABLE oParameters AS "System.Object[]" NO-UNDO . DEFINE VARIABLE oParameterTypes AS "System.Type[]" NO-UNDO . DEFINE VARIABLE uri AS System.Uri NO-UNDO. DEFINE VARIABLE cluster AS Couchbase.Cluster NO-UNDO. DEFINE VARIABLE bucket AS Couchbase.Core.IBucket NO-UNDO. DEFINE VARIABLE clientConfiguration AS Couchbase.Configuration.Client.ClientConfiguration NO-UNDO. DEFINE VARIABLE uriList AS CLASS "System.Collections.Generic.List " NO-UNDO. DEFINE VARIABLE operationResult AS CLASS "Couchbase.OperationResult " NO-UNDO. DEFINE VARIABLE sysObj AS System.object NO-UNDO. DEFINE VARIABLE jObject AS Newtonsoft.Json.Linq.JObject NO-UNDO. uri = NEW System.Uri (" hmrdevntccq01.wkrainier.com:8091"). uriList = NEW "System.Collections.Generic.List " (). uriList:Add(uri). clientConfiguration = NEW Couchbase.Configuration.Client.ClientConfiguration ( ). clientConfiguration:Servers = uriList. cluster = NEW Couchbase.Cluster(clientConfiguration). bucket = cluster:OpenBucket("travel-sample"). // Define an array filled with System.Type to define the .net type of the return value oObjectTypeOfArray = CAST (System.Array:CreateInstance (Progress.Util.TypeHelper:GetType("System.Type"), 1), "System.Type[]") . // fill the methodtype array with the type of objects that the method returns oObjectTypeOfArray:SetValue (Progress.Util.TypeHelper:GetType ("Newtonsoft.Json.Linq.JObject"), 0) . // Define an array filled with System.Object to hold the parameter values for the dynamic method oParameters = CAST (System.Array:CreateInstance (Progress.Util.TypeHelper:GetType("System.Object"), 1), "System.Object[]") . // Define an array filled with System.Type to hold the parameter types for the dynamic method (system.String, System.Int, etc. oParameterTypes = CAST (System.Array:CreateInstance (Progress.Util.TypeHelper:GetType("System.Type"), 1), "System.Type[]"). // fill the parameter arrays with the values and their .net types oParameterTypes:SetValue (Progress.Util.TypeHelper:GetType ("System.String"), 0) . oParameters:SetValue ( ("airline_10"), 0) . // Get the system.type of the parent object oObjectType = bucket:GetType () . // Find the method by name with the correct signature based on the parameters in the type array oMethodInfo = oObjectType:GetMethod ("Get", oParameterTypes) . // make a generic method that returns the types in the objectTypeArray oGenericMethod = oMethodInfo:MakeGenericMethod (oObjectTypeOfArray) . sysObj = oGenericMethod:Invoke (bucket, oParameters) . operationResult = CAST (sysObj, "Couchbase.OperationResult "). jObject = operationResult:Value. IF operationResult:Success THEN MESSAGE jObject:GetValue("name") VIEW-AS ALERT-BOX. ELSE MESSAGE "ERROR: " operationResult:STATUS VIEW-AS ALERT-BOX. RETURN.
Continue reading...
Continue reading...