Ejemplo n.º 1
0
        static public Object GetInstance(string assemblyName, string fullClassName, Object[] constructorArgs)
        {
            GXLogging.Debug(log, "GetInstance '" + fullClassName + "', assembly '" + assemblyName + "'");
            try{
#if NETCORE
                var      asl       = new AssemblyLoader(FileUtil.GetStartupDirectory());
                Assembly assem     = asl.LoadFromAssemblyPath(Path.Combine(FileUtil.GetStartupDirectory(), assemblyName + ".dll"));
                Type     classType = assem.GetType(fullClassName, true, true);
#else
                Assembly assem     = Assembly.Load(new AssemblyName(assemblyName));
                Type     classType = assem.GetType(fullClassName, false, true);
#endif
                return(Activator.CreateInstance(classType, constructorArgs));
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Error in invoke GetInstance", e);
#if !NETCORE
                if (!GxContext.isReorganization)
                {
                    GXUtil.WinMessage(e.Message, string.Empty);
                }
#endif
                throw GxClassLoaderException.ProcessException(e);
            }
        }
Ejemplo n.º 2
0
 static public void ExecuteRef(object o, string mthd, Object[] args)
 {
     GXLogging.Debug(log, "ExecuteRef '" + "class '" + o + "' mthd '" + mthd + "'");
     try
     {
         MethodInfo mth = o.GetType().GetMethod(mthd);
         mth.Invoke(o, args);
     }
     catch (Exception e)
     {
         GXLogging.Error(log, "Error in ExecuteRef ", e);
         throw GxClassLoaderException.ProcessException(e);
     }
 }
Ejemplo n.º 3
0
        static public void ExecuteVoidRef(object o, string mthd, Object[] args)
        {
            try
            {
                MemberInfo[] mth = o.GetType().GetMember(mthd);

                MethodInfo mi = null;

                if (mth != null && mth.Length > 0)
                {
                    if (mth.Length > 1)
                    {
                        for (int i = 0; i < mth.Length; i++)
                        {
                            if (((MethodInfo)mth[i]).ReturnType.ToString() == "System.Void")
                            {
                                mi = (MethodInfo)mth[i];
                                break;
                            }
                        }
                    }
                    else
                    {
                        mi = (MethodInfo)mth[0];
                    }

                    ParameterModifier[] pms = new ParameterModifier[args.Length];
                    ParameterInfo[]     pis = mi.GetParameters();
                    for (int i = 0; i < pis.Length; i++)
                    {
                        ParameterInfo     pi = pis[i];
                        ParameterModifier pm = new ParameterModifier(3);
                        pm[0]  = ((pi.Attributes & ParameterAttributes.In) != ParameterAttributes.None);
                        pm[1]  = ((pi.Attributes & ParameterAttributes.Out) != ParameterAttributes.None);
                        pm[2]  = pi.ParameterType.IsByRef;
                        pms[i] = pm;
                    }
                    o.GetType().InvokeMember(mthd, BindingFlags.InvokeMethod, null, o, args, pms, null, null);
                }
                else
                {
                    throw new GxClassLoaderException("Method " + mthd + " not found");
                }
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Error in invoke ", e);
                throw GxClassLoaderException.ProcessException(e);
            }
        }
Ejemplo n.º 4
0
        static public void Execute(object instance, string mthd, Object[] args)
        {
            GXLogging.Debug(log, "Execute instance '" + instance + "', mthd '" + mthd + "'");
            MethodInfo mth;

            try
            {
                int    count = args != null ? args.Length : 0;
                Type[] types = new Type[count];
                for (int i = 0; i < count; i++)
                {
                    types[i] = args[i].GetType();
                }
                mth = instance.GetType().GetMethod(mthd, types);
                mth.Invoke(instance, args);
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Error in invoke ", e);
                throw GxClassLoaderException.ProcessException(e);
            }
        }