By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,882 Members | 2,482 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,882 IT Pros & Developers. It's quick & easy.

How to convert C# source to CodeDom graph?

P: n/a
I'm playing with CodeDOM and CSharpCodeProvider. I've found the following

CodeDOM -> Assembly
C# Source code -> Assembly

I miss the C# Source code -> CodeDOM only. Is it there? Or it's hidden under
the hood?
Jan 25 '06 #1
Share this Question
Share on Google+
3 Replies

P: n/a
As I know in VS2003 method in CSharpCodeDomProvider.CreateParser is not
overridden thus it is always call base implementation that returns
In VS2005 CSharpCodeDomProvider.CreateParser is marked as obsolette but
CSharpCodeDomProvider.Parse method is not implemented

Jan 25 '06 #2

P: n/a
That means, I have to write C# parser myself?
Are there free available implementations already?
Jan 25 '06 #3

P: n/a
"Alexey Lavnikov" wrote:
That means, I have to write C# parser myself?

Unless you manage to find an existing implementatation, yes. The problem
with a "CSharpToCodeDom" parser is the vastly different expression space of
C# and CodeDom. Some C# expressions are nearly impossible to recreate in
CodeDom. An example:

obj as IDisposable

A possible equivalent would be
obj is IDisposable ? (IDisposable)obj : (IDisposable)null;

Of course, the expression (boolean ? expr1 : expr2) also has no equivalent.

You'd have to introduce a method.

internal T As<T>(object value)
if (value != null &&
return (T)value;
return null;

internal T Or<T>(bool condition,
T trueExpression, T falseExpression)
if (condition)
return trueExpression;
return falseExpression;
// equivalent to: obj as IDisposable

// equivalent to: boolean ? expr1 : expr2
Or(boolean, expr1, expr2)

I've no idea how to replicate the checked statement. Other expressions are
just cumbersome to replicate, e.g. is, foreach, using, lock.


PS: I've found one implementation of ICodeParser:
Microsoft.VisualStudio.Designer.CodeDom.VsCodeDomP arser in the assembly
Microsoft.VisualStudio. My guess is that the Form Designer uses that.
Feb 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.