473,700 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert C# source to CodeDom graph?

I'm playing with CodeDOM and CSharpCodeProvi der. 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 4849
As I know in VS2003 method in CSharpCodeDomPr ovider.CreatePa rser is not
overridden thus it is always call base implementation that returns
null.
In VS2005 CSharpCodeDomPr ovider.CreatePa rser is marked as obsolette but
CSharpCodeDomPr ovider.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 implementatatio n, yes. The problem
with a "CSharpToCodeDo m" 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)ob j : (IDisposable)nu ll;
[/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).IsAss ignableFrom(val ue.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.Visua lStudio.Designe r.CodeDom.VsCod eDomParser in the assembly
Microsoft.Visua lStudio. 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
1917
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? And how to configure the CodeDom to generate code without @-tags? Ron A short example follows whic produces following kind of output:
0
1495
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 and in an On Open event on the report it is on, add the Row Source SELECT statement for that particular application of the graph. I have tried, but couldn't get a property for Row Source. Is what I am trying to do possible, and if so, how do you...
2
2927
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 it's really, really very complicated. So, if there would be a existing tool that converts the C# file to XML it should be easier to parse then the XML file. Because the CreateParser method of the CodeDomProvider class does not work, I now try to...
3
2344
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 MSDN documentation. Thanks in advance, ________________________
2
3669
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 static int Rule001() { return 1; } ==> ILGenerator methodIL = ruleMethod.GetILGenerator(); methodIL.Emit(OpCodes.Ldc_I4, 1); methodIL.Emit(OpCodes.Ret) Thanks.
6
1885
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 Long Sub DrawUsage(lUsage As Long, picPercent As PictureBox, picGraph As
2
2235
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; } One workaround is to use a CodeSnippetExpression and output the literal
0
995
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 load source into CodeDOM? Thanks for any hints, Urs.
2
2281
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 trying to pass this list to an executable section of code which is compiled during run-time. The formulas are calculated in CodeDom and the result is returned on the same List<CellData> object I passed. The user-defined class which holds the cell data...
0
8713
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8639
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9203
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9059
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7795
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6556
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.