473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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
possibilities:

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 4830
As I know in VS2003 method in CSharpCodeDomProvider.CreateParser is not
overridden thus it is always call base implementation that returns
null.
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:

[C#]
obj as IDisposable
[/C#]

A possible equivalent would be
[C#]
obj is IDisposable ? (IDisposable)obj : (IDisposable)null;
[/C#]

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

You'd have to introduce a method.

[CodeDom]
internal T As<T>(object value)
{
if (value != null &&
typeof(T).IsAssignableFrom(value.GetType())
return (T)value;
else
return null;
}

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

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

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

Mark

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ron Bullman | last post by:
Hi, I havent been able to find any documentation about @ in the CodeDom context. The problem is when generating C# code from CodeDom it will associate a @-tag with all C# specific types. Why?...
0
by: dixie | last post by:
I have a rather large graph that I could use a number of times with a slightly different Row Source value. I am trying to keep the size of my application down and I wondered can I use one graph...
2
by: Robert Fischbacher | last post by:
Hello, does anybody know if there is a existing tool that can convert valid C# Code to a XML structure? I tried to parse a C# program to analyze the structure of the existing program code, but...
3
by: Ramiro Calderón | last post by:
Hi list, Does anybody know if there is a way to build a CodeDom Graph given a some *.cs file? I know how to create a *.cs file from a CodeDom graph, and I couldn't find something alike in the...
2
by: Striped | last post by:
Is there any tool to convert source code, e.g. of a C# method, to opcodes being used in System.Reflection.Emit? It's a real pain to do that manually, especially for big pieces of code. public...
6
by: yxq | last post by:
Hello Can anyone convert the vb6 code to vb.net? Thank you! ************************************************************** Const SPACE = 5 Const BAR_WIDTH = 50 Public GraphPoints(0 To 99) As...
2
by: Venkat | last post by:
Hi, Can anyone let me know how to declare a local const in a method using CodeDOM? I am trying to get an output that looks like this: public void SomeMethod() { const int MyInteger = 56; } ...
0
by: Urs | last post by:
Hi I easily can generate C# code using codeDOM, but couldn't figure out how to start with an existing source file, in order to maintain and add new methods/properties at a later stage. How do I...
2
by: CodeMonkey775 | last post by:
I'm having problems passing a variable to a method which is executed and compiled using CodeDom. The situation is I have a List<CellData> with cells, each containing a formula (like Excel). I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.