471,318 Members | 3,268 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

How to convert C# source to CodeDom graph?

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
3 4707
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
That means, I have to write C# parser myself?
Are there free available implementations already?
Jan 25 '06 #3
"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.

Similar topics

reply views Thread by Ron Bullman | last post: by
2 posts views Thread by Robert Fischbacher | last post: by
3 posts views Thread by Ramiro Calderón | last post: by
6 posts views Thread by yxq | last post: by
reply views Thread by Urs | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.