I'm not sure why you choosed such a hard way to do it.
Why not just put a static varialbe in class A as the default value, and assign it to field in the constructor?public class A
{
public string DefaultValue = "hehe";
private string field;
publi A(){
field = DefaultValue;
}
}==============================
http://blog.joycode.com/qqchen
Why not just put a static varialbe in class A as the default value, and assign it to field in the constructor?public class A
{
public string DefaultValue = "hehe";
private string field;
publi A(){
field = DefaultValue;
}
}==============================
http://blog.joycode.com/qqchen
解决方案 »
- 二维or 一维数组赋值
- 高手请进!!!
- watin
- 如何可以将一个表(学生表)转换成SQL Server 数据库中的表?
- 怎样在DataGridView中定位一行
- DateTime转换问题???
- 有用过DevExpress套件的朋友吗?
- 大家好!谁知道C# 2005 WinForm程序设计的教程能不能共享一下,或者告诉一个下载的地址
- 关于sendmessage的问题!!!!!!!!!!!!!!!!!!!!!!!
- 远程版本控制请问用什么软件?
- 如何解决c#中使用继承窗体后重新编译发生的尺寸变化问题。。
- 类型或命名空间名称“Management”在类或命名空间“System”中不存在(是否缺少程序集引用?)
我试过用static变量:
public class A
{
private static string field="hehe";
publi A(){ }
}
然后要反射动态修改field的值,但如果客户端卸载了应用程序域后,static变量的值丢失,下次启动程序的时候,field的值还是"hehe"。
所以我想通过动态修改代码的方法来实现。也就是每次修改field值的时候能先remove private static string field="hehe";然后再add private static string field="haha";
不然哪天换台电脑的时候怎么办.
http://www.codeproject.com/csharp/livecodedotnet.asp
我就是用的文件io来替代完成的,困难不是很大。用了点小技巧把页面交换努力降到最底,但效率上应该还是有差异的。我现在只是想知道类似的技术应该怎么实现,起码用在一些自动生成系统上还是很方便的:
1。如何用ICodeGenerator实现add, remove一个字段的声明及初始化默认值;
2。能不能用反射实现。setvalue我试过,但充其量只能在运行时修改当时内存中静态存储区的值。当客户端unload appdomain后,难道还要重新再运行一次这段代码吗?setvalue并没有从本质上修改源代码啊。或者是不是有类似于setFieldDefaultValue的方法?~~~~~~~
大家再发表意见看^_^
我看过了,还是那个问题啊。setvalue充其量只能在运行时修改当时内存中静态存储区的值。当客户端unload appdomain后,难道还要重新再运行一次这段代码吗?setvalue并没有从本质上修改源代码啊。或者是不是有类似于setFieldDefaultValue的方法?~~~~~~~难道这儿的大哥们都不用ICodeGenerator的吗?期待有个例子,我找不到啊^_^
[email protected]
我是在学习一些源码自动生成平台时发现的这些东东。
其实实现也不是很难,net类库对C#,VB.NET的支持已经很好,只是很烦琐而已。
Reflection.Emit要写IL代码,ICodeGenerator基本上是提取出代码中的各个成分,造成主文件很长,很难读。
谢谢大家的回答,谢谢qqchen79和ArLi2003!^_^
结帐~~~~~~