tringBuilder classSource = new StringBuilder();
classSource.Append("public class DynamicClass \n");
classSource.Append("{\n");
//创建属性。
classSource.Append(propertyString("aaa"));
classSource.Append(propertyString("bbb"));
classSource.Append(propertyString("ccc"));
classSource.Append("}");
System.Diagnostics.Debug.WriteLine(classSource.ToString());
//编译代码。
CompilerResults result = provider.CompileAssemblyFromSource(paras, classSource.ToString());
//获取编译后的
程序集。
Assembly assembly = result.CompiledAssembly; [Page]
return assembly;
}
private static string propertyString(string propertyName)
{
StringBuilder sbProperty = new StringBuilder();
sbProperty.Append(" private int _" + propertyName + " = 0;\n");
sbProperty.Append(" public int " + "" + propertyName + "\n");
sbProperty.Append(" {\n");
sbProperty.Append(" get{ return _" + propertyName + ";} \n");
sbProperty.Append(" set{ _" + propertyName + "&nbs