反射创建对象,执行指定方法

Type type = Type.GetType(m.AssemblyName);
                    ConstructorInfo c = null;
                    object obj;
                    if (m.ParamList != null && m.ParamList.Length > 0)
                    {
                        object[] psv = new object[m.ParamList.Length];
                        Type[] tps = new Type[m.ParamList.Length];
                        for (int i = 0; i < m.ParamList.Length; i++)
                        {
                            tps[i] = Type.GetType(m.ParamList[i].AssemblyName);
                            var Parse = tps[i].GetMethod("Parse", new Type[] { typeof(string) });


                            psv[i] = Parse.Invoke(null, new object[] { m.ParamList[i].ParamValue });
                        }
                        c = type.GetConstructor(tps);
                        obj = c.Invoke(psv);
                    }
                    else
                    {
                        c = type.GetConstructor(new Type[] { });
                        obj = c.Invoke(null);
                    }

你可能感兴趣的:(c#)