As a little experiment, I wrote some code that edits one of its own class files.
Specifically:
namespace Dynamic
{
class DynamicFunction
{
public double Function(double field1, double field2)
{
//Reference
return field1;
//EndReference
}
}
}
I am dynamically editing the 'Function' method through the program itself. So, if one wanted to return field1 % field 2, they would simply type in 'return field1 % field2;', hit a button, and a filestream would edit the actual source code.
However, it seems that this has no effect on the class file until the program is closed, then it takes effect when it is reopened. What's the dealio?
Here's the writing code:
System.IO.File.Delete(path);
using (System.IO.StreamWriter W = new System.IO.StreamWriter(path))
{
foreach (string s in C)
{
if (!s.Contains("return"))
{
W.WriteLine(s);
}
if (s.Contains("return"))
{
W.WriteLine(textBox3.Text);
}
}
}
int r = 0;