StrCode = strCode.Substring( 0, intI + 7) + Int intI = strCode.IndexOf( " " + " MYSELF") StreamWriter sw = new StreamWriter(strFilePath) StrFilePath = Path.Combine(strDirectory, " SelfReplication.cs") Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) It searches for any Main method on the compiled assembly, and invokes (executes) this Main method using the FilePath as an argument. If (cr.Errors.HasErrors || cr.Errors.HasWarnings) dll") ĬompilerResults cr = cc.CompileAssemblyFromSource(cp, strSource) StreamReader sr = new StreamReader(strFilePath) ĬodeDomProvider cc = new CSharpCodeProvider() ĬompilerParameters cp = new CompilerParameters() Īssembly.GetEntryAssembly().GetReferencedAssemblies())Ĭp.ReferencedAssemblies.Add(assemblyName.Name + ". When starting the executable again, it compiles this source code and executes it, showing the same user interface!Ī nice test is to delete the executable and compile the generated source code by using Visual Studio or the command line C# compiler:Ĭopy Code private Assembly CompileCSharp( string strFilePath).When starting the executable, it generates its own source code. I wanted to store the source-code for this program into the program itself, and a final spec was to generate this same source code out of the program. And then, one night I went to do some coding. There is this nice project called " C# Script: The Missing Puzzle Piece". BackgroundĪt one point, I wanted a small program to compile some Notepad edited scripts and run them on the fly. Self-replication is any process by which a thing might make a copy of itself.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |