tag:blogger.com,1999:blog-8912334.post-1119631566411935422005-06-24T09:42:00.000-07:002007-02-20T13:44:19.883-08:00self descriptionSomebody ask for the code of the self descripting c# code i've done <a href="http://oraclevsmicrosoft.blogspot.com/2005/01/code-generation-and-self-description.html"> a few times ago here</a> it is :<br /><br /><font face="courier"><br />using System;<br />using System.Collections;<br />using System.ComponentModel;<br />using System.Windows.Forms;<br />using System.CodeDom;<br />using System.CodeDom.Compiler;<br />using Microsoft.CSharp;<br />using System.Collections.Specialized;<br />namespace WindowsApplication2<br />{<br /> /// Main form<br /><br /> public class Form1 : System.Windows.Forms.Form<br /> {<br /> private System.Windows.Forms.Button button2;<br /> private System.Windows.Forms.Button button1;<br /> private System.Windows.Forms.Button bt_itself;<br /> private System.Windows.Forms.RichTextBox rt1;<br /> private System.Windows.Forms.ListBox listBox1;<br /> private System.ComponentModel.Container components = null;<br /><br /> public Form1()<br /> {<br /> //<br /> // Requis pour la prise en charge du Concepteur Windows Forms<br /> //<br /> InitializeComponent();<br /> }<br /><br /> /// Nettoyage des ressources utilisées.<br /> protected override void Dispose( bool disposing )<br /> {<br /> if( disposing )<br /> {<br /> if (components != null)<br /> {<br /> components.Dispose();<br /> }<br /> }<br /> base.Dispose( disposing );<br /> }<br /><br /> #region Code généré par le Concepteur Windows Form<br /> /// &lt;summary&gt;<br /> /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas<br /> /// le contenu de cette méthode avec l'éditeur de code.<br /> /// &lt;/summary&gt;<br /> private void InitializeComponent() {<br /> this.listBox1 = new System.Windows.Forms.ListBox();<br /> this.rt1 = new System.Windows.Forms.RichTextBox();<br /> this.bt_itself = new System.Windows.Forms.Button();<br /> this.button1 = new System.Windows.Forms.Button();<br /> this.button2 = new System.Windows.Forms.Button();<br /> this.SuspendLayout();<br /> // <br /> // listBox1<br /> // <br /> this.listBox1.Location = new System.Drawing.Point(24, 360);<br /> this.listBox1.Name = &quot;listBox1&quot;;<br /> this.listBox1.Size = new System.Drawing.Size(1016, 108);<br /> this.listBox1.TabIndex = 3;<br /> // <br /> // rt1<br /> // <br /> this.rt1.Location = new System.Drawing.Point(24, 16);<br /> this.rt1.Name = &quot;rt1&quot;;<br /> this.rt1.Size = new System.Drawing.Size(632, 328);<br /> this.rt1.TabIndex = 1;<br /> this.rt1.Text = &quot;richTextBox1&quot;;<br /> // <br /> // bt_itself<br /> // <br /> this.bt_itself.Location = new System.Drawing.Point(696, 40);<br /> this.bt_itself.Name = &quot;bt_itself&quot;;<br /> this.bt_itself.Size = new System.Drawing.Size(72, 24);<br /> this.bt_itself.TabIndex = 0;<br /> this.bt_itself.Text = &quot;it self&quot;;<br /> this.bt_itself.Click += new System.EventHandler(this.bt_itself_Click);<br /> // <br /> // button1<br /> // <br /> this.button1.Location = new System.Drawing.Point(696, 8);<br /> this.button1.Name = &quot;button1&quot;;<br /> this.button1.Size = new System.Drawing.Size(72, 24);<br /> this.button1.TabIndex = 0;<br /> this.button1.Text = &quot;genere&quot;;<br /> this.button1.Click += new System.EventHandler(this.button1_Click);<br /> // <br /> // button2<br /> // <br /> this.button2.Location = new System.Drawing.Point(696, 72);<br /> this.button2.Name = &quot;button2&quot;;<br /> this.button2.Size = new System.Drawing.Size(72, 24);<br /> this.button2.TabIndex = 4;<br /> this.button2.Text = &quot;compile&quot;;<br /> this.button2.Click += new System.EventHandler(this.button2_Click);<br /> <br /> // <br /> // Form1<br /> // <br /> this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br /> this.ClientSize = new System.Drawing.Size(1032, 526);<br /> this.Controls.Add(this.button2);<br /> this.Controls.Add(this.listBox1);<br /> this.Controls.Add(this.rt1);<br /> this.Controls.Add(this.button1);<br /> this.Controls.Add(this.bt_itself);<br /> this.Name = &quot;Form1&quot;;<br /> this.Text = &quot;Form1&quot;;<br /> this.Load += new System.EventHandler(this.Form1_Load);<br /> this.ResumeLayout(false);<br /> }<br /> #endregion<br /><br /> /// Point d'entrée principal de l'application.<br /> [STAThread]<br /> static void Main()<br /> {<br /> Application.Run(new Form1());<br /> }<br />// methode de base <br /> string join(string[] arr,string sep)<br /> {string strReturn=&quot;&quot; ;<br /> foreach (string elt in arr)<br /> strReturn += elt+sep;<br /> strReturn.Substring(0,strReturn.Length-sep.Length);<br /> <br /> return strReturn;<br /> }<br /><br /> void seekandreplace(string[] arr,string strSrc,string strReplace)<br /> {<br /> int i=0;<br /> for(i=0;i&lt;=arr.Length-1;i++)<br /> { if(arr[i]==strSrc)<br /> arr[i]=strReplace;<br /> }<br /> }<br /> string format (string str)<br /> {<br /> str = str.Replace(&quot;\\&quot;,&quot;\\\\&quot;);<br /> str = str.Replace(&quot;\&quot;&quot;,&quot;\\\&quot;&quot;);<br /> return str; <br /> }<br /> string joinformat(string[] arr,string sep)<br /> {<br /> string strReturn= &quot;&quot; ;<br /> foreach (string elt in arr)<br /> { strReturn +=format( elt)+sep;}<br /> <br /> strReturn = strReturn.Substring( 0,strReturn.Length-sep.Length);<br /> <br /> return strReturn;<br /> }<br /> private void Form1_Load(object sender, System.EventArgs e)<br /> {<br /> //nothing special here <br /> }<br /><br /> private void button1_Click(object sender, System.EventArgs e)<br /> {// here is starting the main part of the code:<br /> //<br /> //the CodeCompileUnit is the abstract code structure:<br /><br /> // Create a new CodeCompileUnit to contain the program graph<br /> CodeCompileUnit CompileUnit = new CodeCompileUnit();<br /> // Declare a new namespace called Samples.<br /> CodeNamespace Samples = new CodeNamespace(&quot;Samples&quot;);<br /> // Add the new namespace to the compile unit.<br /> CompileUnit.Namespaces.Add( Samples );<br /><br /> // Add the new namespace import for the System namespace.<br /> Samples.Imports.Add( new CodeNamespaceImport(&quot;System&quot;) );<br /><br /> // Declare a new type called Class1.<br /> CodeTypeDeclaration Class1 = new CodeTypeDeclaration(&quot;echo&quot;);<br /> // Add the new type to the namespace's type collection.<br /> Samples.Types.Add(Class1);<br /><br /> //a variable declaration<br /> CodeVariableDeclarationStatement Var = new<br /> CodeVariableDeclarationStatement(&quot;System.String&quot;,&quot;str1&quot;);<br /> // Declare a new code entry point method<br /> CodeEntryPointMethod Start = new CodeEntryPointMethod();<br /> // Create a new method invocation expression.<br /> CodeMethodInvokeExpression cs1 =<br /> new CodeMethodInvokeExpression(<br /> // Call the System.Console.WriteLine method.<br /> <br /> new CodeTypeReferenceExpression(&quot;System.Console&quot;), &quot;ReadLine&quot;);<br /> CodeAssignStatement as1 = new CodeAssignStatement(<br /> new CodeVariableReferenceExpression(&quot;str1&quot;),cs1);<br /><br /> // Create a new method invocation expression.<br /> CodeMethodInvokeExpression cs2 =<br /> new CodeMethodInvokeExpression(<br /> // Call the System.Console.WriteLine method.<br /> new CodeTypeReferenceExpression(&quot;System.Console&quot;), &quot;WriteLine&quot;);<br /> cs2.Parameters.Add(new CodeVariableReferenceExpression(Var.Name));<br /><br /> Start.Statements.Add(Var);<br /> // Add the new method code statement.<br /> Start.Statements.Add( as1);<br /> // Add the new method code statement.<br /> Start.Statements.Add(new CodeExpressionStatement(cs2));<br /><br /> // Add the code entry point method to the type's members collection<br /> Class1.Members.Add( Start );<br /><br /><br /> System.IO.StringWriter Sw = new System.IO.StringWriter();<br /><br /> <br /> Microsoft.CSharp.CSharpCodeProvider provider =<br /> new CSharpCodeProvider();<br /> System.CodeDom.Compiler.ICodeGenerator generator = provider.CreateGenerator(Sw);<br /> CodeGeneratorOptions genOptions = new CodeGeneratorOptions();<br /><br /> // The code generator should insert blank lines <br /> genOptions.BlankLinesBetweenMembers = true;<br /><br /> try<br /> {<br /> generator.GenerateCodeFromCompileUnit(CompileUnit,Sw,genOptions);<br /> }<br /> catch (Exception Exc)<br /> {<br /> System.Windows.Forms.MessageBox.Show (Exc.Message);<br /> }<br /> rt1.Text = Sw.ToString();<br /><br /> }<br /> <br /> private void button2_Click(object sender, System.EventArgs e)<br /> {<br /> Microsoft.CSharp.CSharpCodeProvider provider =<br /> new CSharpCodeProvider();<br /> ///<br />// Compilation <br /> //instanciate csharp compiler<br /> System.CodeDom.Compiler.ICodeCompiler MyCompiler = provider.CreateCompiler();<br /> System.CodeDom.Compiler.CompilerParameters cp = new CompilerParameters();<br /> cp.GenerateExecutable = true;<br /> cp.CompilerOptions= &quot; /target:exe&quot;;<br /> cp.ReferencedAssemblies.AddRange( new string[]{&quot;System.Windows.Forms.dll&quot;,&quot;System.dll&quot;,&quot;System.drawing.dll&quot;,&quot;&quot;});<br /> //where your exe will be saved<br /> cp.OutputAssembly = &quot;c:\\echo.exe&quot;;<br /> // Invoke compilation.<br /> CompilerResults cr = MyCompiler.CompileAssemblyFromSource ( cp,rt1.Text);<br /> //<br /> // Return the results of compilation.<br /><br /> //eventually load compilation output to the listbox (usefull to debug)<br /> listBox1.DataSource=cr.Output;<br /><br /> //where is it? <br /> MessageBox.Show ( cr.PathToAssembly );<br /> }<br /><br /> private void bt_itself_Click(object sender, System.EventArgs e)<br /> {<br /> string[] arr=new string[]{<br />&quot;using System;&quot;,<br />&quot;using System.Collections;&quot;,<br />&quot;using System.ComponentModel;&quot;,<br />&quot;using System.Windows.Forms;&quot;,<br />&quot;using System.CodeDom;&quot;,<br />&quot;using System.CodeDom.Compiler;&quot;,<br />&quot;using Microsoft.CSharp;&quot;,<br />&quot;using System.Collections.Specialized;&quot;,<br />&quot;namespace WindowsApplication2&quot;,<br />&quot;{&quot;,<br />&quot; /// Main form&quot;,<br />&quot;&quot;,<br />&quot; public class Form1 : System.Windows.Forms.Form&quot;,<br />&quot; {&quot;,<br />&quot; private System.Windows.Forms.Button button2;&quot;,<br />&quot; private System.Windows.Forms.Button button1;&quot;,<br />&quot; private System.Windows.Forms.Button bt_itself;&quot;,<br />&quot; private System.Windows.Forms.RichTextBox rt1;&quot;,<br />&quot; private System.Windows.Forms.ListBox listBox1;&quot;,<br />&quot; private System.ComponentModel.Container components = null;&quot;,<br />&quot;&quot;,<br />&quot; public Form1()&quot;,<br />&quot; {&quot;,<br />&quot; //&quot;,<br />&quot; // Requis pour la prise en charge du Concepteur Windows Forms&quot;,<br />&quot; //&quot;,<br />&quot; InitializeComponent();&quot;,<br />&quot; }&quot;,<br />&quot;&quot;,<br />&quot; /// Nettoyage des ressources utilisées.&quot;,<br />&quot; protected override void Dispose( bool disposing )&quot;,<br />&quot; {&quot;,<br />&quot; if( disposing )&quot;,<br />&quot; {&quot;,<br />&quot; if (components != null)&quot;,<br />&quot; {&quot;,<br />&quot; components.Dispose();&quot;,<br />&quot; }&quot;,<br />&quot; }&quot;,<br />&quot; base.Dispose( disposing );&quot;,<br />&quot; }&quot;,<br />&quot;&quot;,<br />&quot; #region Code généré par le Concepteur Windows Form&quot;,<br />&quot; /// &lt;summary&gt;&quot;,<br />&quot; /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas&quot;,<br />&quot; /// le contenu de cette méthode avec l'éditeur de code.&quot;,<br />&quot; /// &lt;/summary&gt;&quot;,<br />&quot; private void InitializeComponent() {&quot;,<br />&quot; this.listBox1 = new System.Windows.Forms.ListBox();&quot;,<br />&quot; this.rt1 = new System.Windows.Forms.RichTextBox();&quot;,<br />&quot; this.bt_itself = new System.Windows.Forms.Button();&quot;,<br />&quot; this.button1 = new System.Windows.Forms.Button();&quot;,<br />&quot; this.button2 = new System.Windows.Forms.Button();&quot;,<br />&quot; this.SuspendLayout();&quot;,<br />&quot; // &quot;,<br />&quot; // listBox1&quot;,<br />&quot; // &quot;,<br />&quot; this.listBox1.Location = new System.Drawing.Point(24, 360);&quot;,<br />&quot; this.listBox1.Name = \&quot;listBox1\&quot;;&quot;,<br />&quot; this.listBox1.Size = new System.Drawing.Size(1016, 108);&quot;,<br />&quot; this.listBox1.TabIndex = 3;&quot;,<br />&quot; // &quot;,<br />&quot; // rt1&quot;,<br />&quot; // &quot;,<br />&quot; this.rt1.Location = new System.Drawing.Point(24, 16);&quot;,<br />&quot; this.rt1.Name = \&quot;rt1\&quot;;&quot;,<br />&quot; this.rt1.Size = new System.Drawing.Size(632, 328);&quot;,<br />&quot; this.rt1.TabIndex = 1;&quot;,<br />&quot; this.rt1.Text = \&quot;richTextBox1\&quot;;&quot;,<br />&quot; // &quot;,<br />&quot; // bt_itself&quot;,<br />&quot; // &quot;,<br />&quot; this.bt_itself.Location = new System.Drawing.Point(696, 40);&quot;,<br />&quot; this.bt_itself.Name = \&quot;bt_itself\&quot;;&quot;,<br />&quot; this.bt_itself.Size = new System.Drawing.Size(72, 24);&quot;,<br />&quot; this.bt_itself.TabIndex = 0;&quot;,<br />&quot; this.bt_itself.Text = \&quot;it self\&quot;;&quot;,<br />&quot; this.bt_itself.Click += new System.EventHandler(this.bt_itself_Click);&quot;,<br />&quot; // &quot;,<br />&quot; // button1&quot;,<br />&quot; // &quot;,<br />&quot; this.button1.Location = new System.Drawing.Point(696, 8);&quot;,<br />&quot; this.button1.Name = \&quot;button1\&quot;;&quot;,<br />&quot; this.button1.Size = new System.Drawing.Size(72, 24);&quot;,<br />&quot; this.button1.TabIndex = 0;&quot;,<br />&quot; this.button1.Text = \&quot;genere\&quot;;&quot;,<br />&quot; this.button1.Click += new System.EventHandler(this.button1_Click);&quot;,<br />&quot; // &quot;,<br />&quot; // button2&quot;,<br />&quot; // &quot;,<br />&quot; this.button2.Location = new System.Drawing.Point(696, 72);&quot;,<br />&quot; this.button2.Name = \&quot;button2\&quot;;&quot;,<br />&quot; this.button2.Size = new System.Drawing.Size(72, 24);&quot;,<br />&quot; this.button2.TabIndex = 4;&quot;,<br />&quot; this.button2.Text = \&quot;compile\&quot;;&quot;,<br />&quot; this.button2.Click += new System.EventHandler(this.button2_Click);&quot;,<br />&quot; &quot;,<br />&quot; // &quot;,<br />&quot; // Form1&quot;,<br />&quot; // &quot;,<br />&quot; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&quot;,<br />&quot; this.ClientSize = new System.Drawing.Size(1032, 526);&quot;,<br />&quot; this.Controls.Add(this.button2);&quot;,<br />&quot; this.Controls.Add(this.listBox1);&quot;,<br />&quot; this.Controls.Add(this.rt1);&quot;,<br />&quot; this.Controls.Add(this.button1);&quot;,<br />&quot; this.Controls.Add(this.bt_itself);&quot;,<br />&quot; this.Name = \&quot;Form1\&quot;;&quot;,<br />&quot; this.Text = \&quot;Form1\&quot;;&quot;,<br />&quot; this.Load += new System.EventHandler(this.Form1_Load);&quot;,<br />&quot; this.ResumeLayout(false);&quot;,<br />&quot; }&quot;,<br />&quot; #endregion&quot;,<br />&quot;&quot;,<br />&quot; /// Point d'entrée principal de l'application.&quot;,<br />&quot; [STAThread]&quot;,<br />&quot; static void Main()&quot;,<br />&quot; {&quot;,<br />&quot; Application.Run(new Form1());&quot;,<br />&quot; }&quot;,<br />&quot;// methode de base &quot;,<br />&quot; string join(string[] arr,string sep)&quot;,<br />&quot; {string strReturn=\&quot;\&quot; ;&quot;,<br />&quot; foreach (string elt in arr)&quot;,<br />&quot; strReturn += elt+sep;&quot;,<br />&quot; strReturn.Substring(0,strReturn.Length-sep.Length);&quot;,<br />&quot; &quot;,<br />&quot; return strReturn;&quot;,<br />&quot; }&quot;,<br />&quot;&quot;,<br />&quot; void seekandreplace(string[] arr,string strSrc,string strReplace)&quot;,<br />&quot; {&quot;,<br />&quot; int i=0;&quot;,<br />&quot; for(i=0;i&lt;=arr.Length-1;i++)&quot;,<br />&quot; { if(arr[i]==strSrc)&quot;,<br />&quot; arr[i]=strReplace;&quot;,<br />&quot; }&quot;,<br />&quot; }&quot;,<br />&quot; string format (string str)&quot;,<br />&quot; {&quot;,<br />&quot; str = str.Replace(\&quot;\\\\\&quot;,\&quot;\\\\\\\\\&quot;);&quot;,<br />&quot; str = str.Replace(\&quot;\\\&quot;\&quot;,\&quot;\\\\\\\&quot;\&quot;);&quot;,<br />&quot; return str; &quot;,<br />&quot; }&quot;,<br />&quot; string joinformat(string[] arr,string sep)&quot;,<br />&quot; {&quot;,<br />&quot; string strReturn= \&quot;\&quot; ;&quot;,<br />&quot; foreach (string elt in arr)&quot;,<br />&quot; { strReturn +=format( elt)+sep;}&quot;,<br />&quot; &quot;,<br />&quot; strReturn = strReturn.Substring( 0,strReturn.Length-sep.Length);&quot;,<br />&quot; &quot;,<br />&quot; return strReturn;&quot;,<br />&quot; }&quot;,<br />&quot; private void Form1_Load(object sender, System.EventArgs e)&quot;,<br />&quot; {&quot;,<br />&quot; //nothing special here &quot;,<br />&quot; }&quot;,<br />&quot;&quot;,<br />&quot; private void button1_Click(object sender, System.EventArgs e)&quot;,<br />&quot; {// here is starting the main part of the code:&quot;,<br />&quot; //&quot;,<br />&quot; //the CodeCompileUnit is the abstract code structure:&quot;,<br />&quot;&quot;,<br />&quot; // Create a new CodeCompileUnit to contain the program graph&quot;,<br />&quot; CodeCompileUnit CompileUnit = new CodeCompileUnit();&quot;,<br />&quot; // Declare a new namespace called Samples.&quot;,<br />&quot; CodeNamespace Samples = new CodeNamespace(\&quot;Samples\&quot;);&quot;,<br />&quot; // Add the new namespace to the compile unit.&quot;,<br />&quot; CompileUnit.Namespaces.Add( Samples );&quot;,<br />&quot;&quot;,<br />&quot; // Add the new namespace import for the System namespace.&quot;,<br />&quot; Samples.Imports.Add( new CodeNamespaceImport(\&quot;System\&quot;) );&quot;,<br />&quot;&quot;,<br />&quot; // Declare a new type called Class1.&quot;,<br />&quot; CodeTypeDeclaration Class1 = new CodeTypeDeclaration(\&quot;echo\&quot;);&quot;,<br />&quot; // Add the new type to the namespace's type collection.&quot;,<br />&quot; Samples.Types.Add(Class1);&quot;,<br />&quot;&quot;,<br />&quot; //a variable declaration&quot;,<br />&quot; CodeVariableDeclarationStatement Var = new&quot;,<br />&quot; CodeVariableDeclarationStatement(\&quot;System.String\&quot;,\&quot;str1\&quot;);&quot;,<br />&quot; // Declare a new code entry point method&quot;,<br />&quot; CodeEntryPointMethod Start = new CodeEntryPointMethod();&quot;,<br />&quot; // Create a new method invocation expression.&quot;,<br />&quot; CodeMethodInvokeExpression cs1 =&quot;,<br />&quot; new CodeMethodInvokeExpression(&quot;,<br />&quot; // Call the System.Console.WriteLine method.&quot;,<br />&quot; &quot;,<br />&quot; new CodeTypeReferenceExpression(\&quot;System.Console\&quot;), \&quot;ReadLine\&quot;);&quot;,<br />&quot; CodeAssignStatement as1 = new CodeAssignStatement(&quot;,<br />&quot; new CodeVariableReferenceExpression(\&quot;str1\&quot;),cs1);&quot;,<br />&quot;&quot;,<br />&quot; // Create a new method invocation expression.&quot;,<br />&quot; CodeMethodInvokeExpression cs2 =&quot;,<br />&quot; new CodeMethodInvokeExpression(&quot;,<br />&quot; // Call the System.Console.WriteLine method.&quot;,<br />&quot; new CodeTypeReferenceExpression(\&quot;System.Console\&quot;), \&quot;WriteLine\&quot;);&quot;,<br />&quot; cs2.Parameters.Add(new CodeVariableReferenceExpression(Var.Name));&quot;,<br />&quot;&quot;,<br />&quot; Start.Statements.Add(Var);&quot;,<br />&quot; // Add the new method code statement.&quot;,<br />&quot; Start.Statements.Add( as1);&quot;,<br />&quot; // Add the new method code statement.&quot;,<br />&quot; Start.Statements.Add(new CodeExpressionStatement(cs2));&quot;,<br />&quot;&quot;,<br />&quot; // Add the code entry point method to the type's members collection&quot;,<br />&quot; Class1.Members.Add( Start );&quot;,<br />&quot;&quot;,<br />&quot;&quot;,<br />&quot; System.IO.StringWriter Sw = new System.IO.StringWriter();&quot;,<br />&quot;&quot;,<br />&quot; &quot;,<br />&quot; Microsoft.CSharp.CSharpCodeProvider provider =&quot;,<br />&quot; new CSharpCodeProvider();&quot;,<br />&quot; System.CodeDom.Compiler.ICodeGenerator generator = provider.CreateGenerator(Sw);&quot;,<br />&quot; CodeGeneratorOptions genOptions = new CodeGeneratorOptions();&quot;,<br />&quot;&quot;,<br />&quot; // The code generator should insert blank lines &quot;,<br />&quot; genOptions.BlankLinesBetweenMembers = true;&quot;,<br />&quot;&quot;,<br />&quot; try&quot;,<br />&quot; {&quot;,<br />&quot; generator.GenerateCodeFromCompileUnit(CompileUnit,Sw,genOptions);&quot;,<br />&quot; }&quot;,<br />&quot; catch (Exception Exc)&quot;,<br />&quot; {&quot;,<br />&quot; System.Windows.Forms.MessageBox.Show (Exc.Message);&quot;,<br />&quot; }&quot;,<br />&quot; rt1.Text = Sw.ToString();&quot;,<br />&quot;&quot;,<br />&quot; }&quot;,<br />&quot; &quot;,<br />&quot; private void button2_Click(object sender, System.EventArgs e)&quot;,<br />&quot; {&quot;,<br />&quot; Microsoft.CSharp.CSharpCodeProvider provider =&quot;,<br />&quot; new CSharpCodeProvider();&quot;,<br />&quot; ///&quot;,<br />&quot;// Compilation &quot;,<br />&quot; //instanciate csharp compiler&quot;,<br />&quot; System.CodeDom.Compiler.ICodeCompiler MyCompiler = provider.CreateCompiler();&quot;,<br />&quot; System.CodeDom.Compiler.CompilerParameters cp = new CompilerParameters();&quot;,<br />&quot; cp.GenerateExecutable = true;&quot;,<br />&quot; cp.CompilerOptions= \&quot; /target:exe\&quot;;&quot;,<br />&quot; cp.ReferencedAssemblies.AddRange( new string[]{\&quot;System.Windows.Forms.dll\&quot;,\&quot;System.dll\&quot;,\&quot;System.drawing.dll\&quot;,\&quot;\&quot;});&quot;,<br />&quot; //where your exe will be saved&quot;,<br />&quot; cp.OutputAssembly = \&quot;c:\\\\echo.exe\&quot;;&quot;,<br />&quot; // Invoke compilation.&quot;,<br />&quot; CompilerResults cr = MyCompiler.CompileAssemblyFromSource ( cp,rt1.Text);&quot;,<br />&quot; //&quot;,<br />&quot; // Return the results of compilation.&quot;,<br />&quot;&quot;,<br />&quot; //eventually load compilation output to the listbox (usefull to debug)&quot;,<br />&quot; listBox1.DataSource=cr.Output;&quot;,<br />&quot;&quot;,<br />&quot; //where is it? &quot;,<br />&quot; MessageBox.Show ( cr.PathToAssembly );&quot;,<br />&quot; }&quot;,<br />&quot;&quot;,<br />&quot; private void bt_itself_Click(object sender, System.EventArgs e)&quot;,<br />&quot; {&quot;,<br />&quot; string[] arr=new string[]{&quot;,<br />&quot;Les sanglots longs des violons de l'automne bercent mon coeur d'une langueur monotone&quot;,<br />&quot; };&quot;,<br />&quot; seekandreplace(arr,\&quot;Les sanglots longs des violons de l'automne bercent mon coeur d'une langueur monotone\&quot;,\&quot;\\\&quot;\&quot;+joinformat(arr,\&quot;\\\&quot;,\\n\\\&quot;\&quot;)+\&quot;\\\&quot;\&quot;);&quot;,<br />&quot; this.rt1.Text = join(arr,\&quot;\\n\&quot;);&quot;,<br />&quot; }&quot;,<br />&quot; }&quot;,<br />&quot;}&quot;<br /> };<br /> seekandreplace(arr,&quot;Les sanglots longs des violons de l'automne bercent mon coeur d'une langueur monotone&quot;,&quot;\&quot;&quot;+joinformat(arr,&quot;\&quot;,\n\&quot;&quot;)+&quot;\&quot;&quot;);<br /> this.rt1.Text = join(arr,&quot;\n&quot;);<br /> }<br /> }<br />}<br /><br /><br /></font>Marcnoreply@blogger.com