Friday, April 20, 2012

How to call a method using Reflection in C#.net


public static object Reflection_Result(string Method, string DllName, string ClassName, object[] ParametersList)
        {
            object result;
            try
            {
                DllName = DllName.Replace(".dll", "");
                string dll = Path.GetFileName(DllName);

                Assembly assembly = Assembly.LoadFrom(DllName + ".dll");
                object obj1 = assembly.CreateInstance(dll + "." + ClassName);
                Type type1 = obj1.GetType();
                result = type1.GetMethod(Method).Invoke(obj1, ParametersList);
            }
            catch (Exception ex)
            {
                ErrorLogs.SaveError(ex, "COMMON_UTILITY");
                throw ex;
            }
            return result;
        }

No comments: