日期:2014-05-18 浏览次数:21098 次
CSharpCodeProvider p = new CSharpCodeProvider(); CompilerParameters param = new CompilerParameters(new string[] { "System.dll" }); string s = "namespace __ns{public class AAA{ public string name{get{return \"abab\";}} }}"; CompilerResults rel = p.CompileAssemblyFromSource(param, s); Type t = rel.CompiledAssembly.GetType("__ns.AAA"); object o = t.GetConstructor(System.Type.EmptyTypes).Invoke(null); MessageBox.Show(t.GetProperty("name").GetValue(o, null).ToString());