public static Method[] GetMethods(PluginBase plugin) { var result = new List<Method>(); if (plugin == null) return result.ToArray(); var methods = plugin.GetType().GetMethods(); foreach (var me in methods) { var method = new Method(); method.AssemblyName = plugin.GetType().Assembly.ManifestModule.Name; method.NameSpace = plugin.GetType().Namespace; method.ClassName = plugin.GetType().Name; method.MethodName = me.Name; method.Parameters = new Dictionary<string, Parameter>(); foreach (var par in me.GetParameters()) { var parameter = new Parameter(par.ParameterType, par.Name, par.DefaultValue, ParameterDirection.Input); method.Parameters.Add(par.Name, parameter); } method.ReturnParameter = new Parameter(me.ReturnType, "ReturnValue", null, ParameterDirection.ReturnValue); result.Add(method); } return result.ToArray(); }
public static Method[] GetMethods(PluginBase plugin) { var result = new List <Method>(); if (plugin == null) { return(result.ToArray()); } var methods = plugin.GetType().GetMethods(); foreach (var me in methods) { var method = new Method(); method.AssemblyName = plugin.GetType().Assembly.ManifestModule.Name; method.NameSpace = plugin.GetType().Namespace; method.ClassName = plugin.GetType().Name; method.MethodName = me.Name; method.Parameters = new Dictionary <string, Parameter>(); foreach (var par in me.GetParameters()) { var parameter = new Parameter(par.ParameterType, par.Name, par.DefaultValue, ParameterDirection.Input); method.Parameters.Add(par.Name, parameter); } method.ReturnParameter = new Parameter(me.ReturnType, "ReturnValue", null, ParameterDirection.ReturnValue); result.Add(method); } return(result.ToArray()); }
public static Parameter ExecuteMethod(PluginBase plugin, Method method) { var equalsMethodsInClass = plugin.GetMethods().Where(x => x.Equals(method)).OrderByDescending(x => x.Parameters.Count).ToList(); if (equalsMethodsInClass.Count <= 0) { throw new PluginsException(string.Format("Method {0} in class {1} was not found", method.MethodName, plugin.ToString())); } var onlyInputParams = method.Parameters.Where(x => x.Value.Direction == ParameterDirection.Input).ToList(); foreach (var methodInClass in equalsMethodsInClass) { var methodInClassOnlyInput = methodInClass.Parameters.Where(x => x.Value.Direction == ParameterDirection.Input).ToList(); object[] parameters; Type[] types; if (sameParameters(methodInClassOnlyInput, onlyInputParams, out parameters, out types)) { var result = plugin.GetType().GetMethod(method.MethodName, types).Invoke(plugin, parameters); return(getResultFromMethod(method, result)); } } throw new PluginsException(string.Format("Method {0} in class {1} was found, but it has different parameters", method.MethodName, plugin.ToString())); }
public static void SetFields(PluginBase plugin, Field[] fields) { foreach (FieldInfo field in plugin.GetType().GetFields()) { FieldInfo field1 = field; if (fields.Any(x => x.Name.Equals(field1.Name))) { Field fieldIn = fields.Single(x => x.Name.Equals(field1.Name)); field1.SetValue(plugin, fieldIn.Value); } } }
public static Field[] GetFields(PluginBase plugin) { var result = new List<Field>(); if (plugin == null) return result.ToArray(); FieldInfo[] fields = plugin.GetType().GetFields(); foreach (FieldInfo fi in fields) { var oneField = new Field(); oneField.Value = fi.GetValue(plugin); oneField.Name = fi.Name; oneField.FieldType = fi.FieldType; result.Add(oneField); } return result.ToArray(); }
public static Field[] GetFields(PluginBase plugin) { var result = new List <Field>(); if (plugin == null) { return(result.ToArray()); } FieldInfo[] fields = plugin.GetType().GetFields(); foreach (FieldInfo fi in fields) { var oneField = new Field(); oneField.Value = fi.GetValue(plugin); oneField.Name = fi.Name; oneField.FieldType = fi.FieldType; result.Add(oneField); } return(result.ToArray()); }
public static Parameter ExecuteMethod(PluginBase plugin, Method method) { var equalsMethodsInClass = plugin.GetMethods().Where(x => x.Equals(method)).OrderByDescending(x => x.Parameters.Count).ToList(); if (equalsMethodsInClass.Count <= 0) throw new PluginsException(string.Format("Method {0} in class {1} was not found", method.MethodName, plugin.ToString())); var onlyInputParams = method.Parameters.Where(x => x.Value.Direction == ParameterDirection.Input).ToList(); foreach (var methodInClass in equalsMethodsInClass) { var methodInClassOnlyInput = methodInClass.Parameters.Where(x => x.Value.Direction == ParameterDirection.Input).ToList(); object[] parameters; Type[] types; if (sameParameters(methodInClassOnlyInput, onlyInputParams, out parameters, out types)) { var result = plugin.GetType().GetMethod(method.MethodName, types).Invoke(plugin, parameters); return getResultFromMethod(method, result); } } throw new PluginsException(string.Format("Method {0} in class {1} was found, but it has different parameters", method.MethodName, plugin.ToString())); }