Atomia.Web.Plugin.PublicOrder.Helpers.ReflectionHelper.ReflectMethod C# (CSharp) Метод

ReflectMethod() приватный статический Метод

Reflects the method for specified client (theme).
private static ReflectMethod ( string pluginNamespace, string theme, string methodName, List methodParameters, string defaultPluginNamespace ) : object
pluginNamespace string The plugin namespace.
theme string The theme.
methodName string Name of the method.
methodParameters List The method parameters.
defaultPluginNamespace string The default plugin namespace.
Результат object
        private static object ReflectMethod(string pluginNamespace, string theme, string methodName, List<object> methodParameters, string defaultPluginNamespace)
        {
            // Get plugin assembly for specific client containing method for check
            System.Reflection.Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().ToList().Find(a => a.FullName.Contains(pluginNamespace + theme)) ??
                                                  AppDomain.CurrentDomain.GetAssemblies().ToList().Find(a => a.FullName.Contains(defaultPluginNamespace));

            foreach (Type t in assembly.GetTypes())
            {
                var typeInstance = assembly.CreateInstance(t.FullName);
                var methodInfo = t.GetMethod(methodName);

                if (methodInfo != null && typeInstance != null)
                {
                    return (object)methodInfo.Invoke(typeInstance, methodParameters.ToArray());
                }

                // If method does not exist in client plugin, use default
                if (assembly.FullName != defaultPluginNamespace)
                {
                    assembly = AppDomain.CurrentDomain.GetAssemblies().ToList().Find(a => a.FullName.Contains(defaultPluginNamespace));
                    foreach (Type td in assembly.GetTypes())
                    {
                        typeInstance = assembly.CreateInstance(td.FullName);
                        methodInfo = td.GetMethod(methodName);

                        if (methodInfo != null && typeInstance != null)
                        {
                            return (object)methodInfo.Invoke(typeInstance, methodParameters.ToArray());
                        }
                    }
                }

                throw new NullReferenceException(String.Format("Assembly:{0}, Method:{1}", pluginNamespace + theme, methodName));
            }

            return null;
        }