コード例 #1
0
 public object staticInvocation(string assemblyToUse, string typeToLoad, string methodToExecute,
                                object[] methodParams)
 {
     try
     {
         //Assembly assembly = AppDomain.CurrentDomain.Load(assemblyToUse);
         var assembly = assemblyToUse.assembly();
         if (assembly == null)
         {
             DI.log.error("in staticInvocation assembly was null : {0} {1}", assemblyToUse);
         }
         else
         {
             Type type = DI.reflection.getType(assembly, typeToLoad);
             if (type == null)
             {
                 DI.log.error("in staticInvocation type was null : {0} {1}", assembly, typeToLoad);
             }
             else
             {
                 MethodInfo method = DI.reflection.getMethod(type, methodToExecute, methodParams);
                 if (method == null)
                 {
                     DI.log.error("in staticInvocation method was null : {0} {1}", type, methodToExecute);
                 }
                 else
                 {
                     if (InvokeInStaThread)
                     {
                         O2Kernel_O2Thread.staThread(
                             () => DI.reflection.invoke(null, method, methodParams));
                     }
                     else if (InvokeInMtaThread)
                     {
                         O2Kernel_O2Thread.mtaThread(
                             () => DI.reflection.invoke(null, method, methodParams));
                     }
                     else
                     {
                         return(DI.reflection.invoke(null, method, methodParams));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DI.log.ex(ex, "in instanceInvocation");
     }
     return(null);
 }
コード例 #2
0
        public object instanceInvocation(string assemblyToUse, string typeToLoad, string methodToExecute,
                                         object[] methodParams)
        {
            try
            {
                Assembly assembly = AppDomain.CurrentDomain.Load(assemblyToUse);
                if (assembly == null)
                {
                    DI.log.error("in instanceInvocation assembly was null : {0} {1}", assemblyToUse);
                }
                else
                {
                    Type type = DI.reflection.getType(assembly, typeToLoad);
                    if (type == null)
                    {
                        DI.log.error("in instanceInvocation type was null : {0} {1}", assembly, typeToLoad);
                    }
                    else
                    {
                        object typeObject = DI.reflection.createObject(assembly, type, methodParams);
                        if (typeObject == null)
                        {
                            DI.log.error("in dynamicInvocation typeObject was null : {0} {1}", assembly, type);
                        }
                        else
                        {
                            if (methodToExecute == "")
                            {
                                // means we don't want to execute a method (i.e we called the constructore) so just want the current proxy
                                return(typeObject);
                            }
                            MethodInfo method = DI.reflection.getMethod(type, methodToExecute, methodParams);
                            if (method == null)
                            {
                                DI.log.error("in instanceInvocation method was null : {0} {1}", type, methodToExecute);
                            }
                            else
                            {
                                if (InvokeInStaThread)
                                {
                                    return(O2Kernel_O2Thread.staThread(
                                               () => DI.reflection.invoke(typeObject, method, methodParams)));
                                }
                                if (InvokeInMtaThread)
                                {
                                    return(O2Kernel_O2Thread.mtaThread(
                                               () => DI.reflection.invoke(typeObject, method, methodParams)));
                                }

                                return(DI.reflection.invoke(typeObject, method, methodParams));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in instanceInvocation");
            }
            return(null);
        }