J
JT
Sorry if my frustration shows through in this. I have seen posts and
discussions dating back to 2001 and still haven't seen any "good"
example of a tutorial on CodeDOM. I've seen very many that give the
same Console.WriteLine("Hello, World."); example. If that's all you
want to do, then maybe it's adequate. The very first thing I've tried
to do is use a MessageBox instead. When I include System.dll
in .ReferencedAssemblies I get an error saying that Windows doesn't
exist in System. Therefore, Forms is just a distant dream.
The other disheartening thing is that most of the examples deal with
CSharpCodeProvider, which is obsolete in .NET 2.0, so I don't want to
use that if it's going away. I've copied the 3 or 4 best examples
I've found in this group and tried to work with those and have had no
luck. Can someone please point me to a tutorial that uses the newer
class, , and that does something more complex than a WriteLine(), and
maybe that compiles to memory instead of creating a physical dll?
I want to be able to compile and run code from a string. While direct
help with this problem would be appreciated, I'd really like a good
and complete reference. Here's what I've been playing with:
CodeDomProvider cdpTemp =
CodeDomProvider.CreateProvider("CSharp");
System.CodeDom.Compiler.CompilerParameters cpTemp = new
CompilerParameters();
cpTemp.GenerateExecutable = false;
cpTemp.GenerateInMemory = true;
cpTemp.ReferencedAssemblies.Add("System.dll");
string[] saSourceStrings = new string[1];
saSourceStrings[0] = Photos.Resource1.CodeSnippet;
CompilerResults crTemp =
cdpTemp.CompileAssemblyFromSource(cpTemp, saSourceStrings);
System.Reflection.Assembly asmTemp =
crTemp.CompiledAssembly;
Type tTemp = asmTemp.GetType();
tTemp.GetMethod("ShowAMessage");
ShowAMessage is a method that just uses MessageBox to display a hard-
coded string. Not too difficult, right?
Thanks!
discussions dating back to 2001 and still haven't seen any "good"
example of a tutorial on CodeDOM. I've seen very many that give the
same Console.WriteLine("Hello, World."); example. If that's all you
want to do, then maybe it's adequate. The very first thing I've tried
to do is use a MessageBox instead. When I include System.dll
in .ReferencedAssemblies I get an error saying that Windows doesn't
exist in System. Therefore, Forms is just a distant dream.
The other disheartening thing is that most of the examples deal with
CSharpCodeProvider, which is obsolete in .NET 2.0, so I don't want to
use that if it's going away. I've copied the 3 or 4 best examples
I've found in this group and tried to work with those and have had no
luck. Can someone please point me to a tutorial that uses the newer
class, , and that does something more complex than a WriteLine(), and
maybe that compiles to memory instead of creating a physical dll?
I want to be able to compile and run code from a string. While direct
help with this problem would be appreciated, I'd really like a good
and complete reference. Here's what I've been playing with:
CodeDomProvider cdpTemp =
CodeDomProvider.CreateProvider("CSharp");
System.CodeDom.Compiler.CompilerParameters cpTemp = new
CompilerParameters();
cpTemp.GenerateExecutable = false;
cpTemp.GenerateInMemory = true;
cpTemp.ReferencedAssemblies.Add("System.dll");
string[] saSourceStrings = new string[1];
saSourceStrings[0] = Photos.Resource1.CodeSnippet;
CompilerResults crTemp =
cdpTemp.CompileAssemblyFromSource(cpTemp, saSourceStrings);
System.Reflection.Assembly asmTemp =
crTemp.CompiledAssembly;
Type tTemp = asmTemp.GetType();
tTemp.GetMethod("ShowAMessage");
ShowAMessage is a method that just uses MessageBox to display a hard-
coded string. Not too difficult, right?
Thanks!