473,382 Members | 1,420 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,382 software developers and data experts.

Problems with CodeDom and CSharpCodeProvider

Hello

I am making an application that generates source code. I am facing some
problems.

1- How can I generate code that uses the c# 'params' keyword to specify
multiple arguments?
I tried 2 ways
method.Parameters.Add(new CodeParameterDeclarationExpression("params
object[]", name));
and
method.Parameters.Add(new
CodeParameterDeclarationExpression(typeof(object[]), name));
CodeAttributeDeclaration attr = new CodeAttributeDeclaration();
attr.Name = "ParamArrayAttribute";
method.Parameters[2].CustomAttributes.Add(attr);

The problem with the first way is that it will not work with generating
other languages (such as VB.NET), but it works fine with c#
The problem with the second method, is that ParamArrayAttribute can't be
use in c# so the generated code will not compile. I compiles in VB

2- I want to generate a while loop, but it seems that only for can be
generated. Here is an example
CodeIterationStatement Loop = new CodeIterationStatement();
Loop.InitStatement = new CodeSnippetStatement("");
Loop.IncrementStatement = new CodeSnippetStatement("");
Loop.TestExpression = Invoke(VarRef("reader"), "Read");
If I leave InitStatement and IncrementStatement code generation fails
with a NullReference exception, the above code generates

for (
; reader.Read();
)
Although this is equivalent to while(reader.Read()), but it doesn't look
nice. Also do-while loops are not supported. I know that they can be
implemented with goto, but it will not look good either. I would like to
know also how can I generate continue and break?

3- Is switch / case supported by CodeDom in anyway?

4- When strings in generated code are very long, they are divided to several
lines, I don't want this, or at least I can control it.
for example CSharpCodeProvider would generate "Hel" + "lo World" I would
rather make it "Hello " + "World"

5- JSharpCodeProvider would translate primitive types to keywords sometimes
when it is not appropriate. Ex.
new CodeFieldReferenceExpression(new
CodeTypeReferenceExpression(typeof(int)), "MinValue")
whould generate int.MinValue which produces a compiler error. It should be
System.Int32.MinValue

6 - Some of the class return file extensions with a '.' and some don't. For
example CSharpCodeProvider returns "cs" while VJSharpCodeProvider returns
".jsl". This is a very minor problem, and easy to solve, I have my code
check for the existence of '.' in the extension. But I think all classes
must be consistent.
To Solve all the above problems, I wanted to inherit the CSharpCodeGenerator
that does this, but I found that it is internal, and there is no way I can
have acces to it.
Sorry for my long post, and my bad english. And thanks a lot for taking time
to read this.

Best regards,
Sherif
Nov 16 '05 #1
0 2936

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: Sherif ElMetainy | last post by:
Hello I am making an application that generates source code. I am facing some problems. 1- How can I generate code that uses the c# 'params' keyword to specify multiple arguments? I tried 2...
3
by: Alexey Lavnikov | last post by:
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?...
2
by: JT | last post by:
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...
6
by: moondaddy | last post by:
will CodeDom create XAML windows or just regular windows forms? If so, how to I tell it to create a xaml window instead of a windows form? thanks -- moondaddy@noemail.noemail
2
by: Chuck B | last post by:
I have an object factory that creates customized objects with a method that is dependant on the name of the object. Much of the method is similar but some parameters within the method will be added...
1
by: Niels Ull | last post by:
Hi! I'm using .Net 2.0 and C#, and I'm trying to generate code for build time AOP. But I cannot find out how to generate an anonymous delegate. E.g. generating code like this: class...
0
by: senglory | last post by:
I wrote in web.config the following lines: <system.web> <customErrors mode="Off"/> </system.web>
0
by: thisismykindabyte | last post by:
Hello, I was wondering if anyone might know the easiest way to access static methods through a namespace(MyNamespace) from CodeDom generated code? Basically I have this in my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.