Still looking for a good tutorial on CodeDOM

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!
 
M

Michael Nemtsev

Hello JT,

try this one "Microsoft .NET CodeDom Technology"
part1: http://www.15seconds.com/issue/020917.htm
part2: http://www.15seconds.com/issue/021113.htm

J> Sorry if my frustration shows through in this. I have seen posts and
J> discussions dating back to 2001 and still haven't seen any "good"
J> example of a tutorial on CodeDOM. I've seen very many that give the
J> same Console.WriteLine("Hello, World."); example. If that's all you
J> want to do, then maybe it's adequate. The very first thing I've
J> tried
---
WBR, Michael Nemtsev [C# MVP]. Blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangel
 
J

JT

Hi Michael,

While I'm not sure if this will fit my needs, I'm sure it will help me
to understand the technology since it provides a new example and is a
more indepth analysis and explanation. If you run across an example
that will compile soure from a string (.CompileAssemblyFromSource) I
would like to see it. But this may point out my errors enough to get
me past the hurdle. I just think my test code was simple enough that
it should have worked.

Your recommendation is greatly appreciated.

JT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top