473,395 Members | 1,652 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,395 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 2940

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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.