473,505 Members | 15,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to declare a local const (inside a method) using CodeDOM ?

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
"const" keyword. But that'll make it specific to C#. I prefer to keep
the output language option flexible.

Thanks in advance for your help.
-Venkat

Sep 6 '06 #1
2 2224
Venkat,

I'm not sure if this would work, but have you tried attaching a
CodeMemberField for the constant to the function code graph?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Venkat" <sv********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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
"const" keyword. But that'll make it specific to C#. I prefer to keep
the output language option flexible.

Thanks in advance for your help.
-Venkat

Sep 6 '06 #2
Hi Nicholas,
Thanks for your response. Yes, I already checked that and
CodeMemberMethod cannot contain a CodeMemberFiled; only "Statement" is
allowed :-(

-Venkat

Nicholas Paldino [.NET/C# MVP] wrote:
Venkat,

I'm not sure if this would work, but have you tried attaching a
CodeMemberField for the constant to the function code graph?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Venkat" <sv********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
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
"const" keyword. But that'll make it specific to C#. I prefer to keep
the output language option flexible.

Thanks in advance for your help.
-Venkat
Sep 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
30543
by: The8thSense | last post by:
how to declare static varible and static method inside a class ? i try "public static ABC as integer = 10" and it said my declaration is invalid Thanks
14
2321
by: J.S. | last post by:
In a Windows Form application, which is the better method to concatenate large blocks of code? 1. Reading the text from text files. 2. Adding the text to the VB file itself? Thanks! J.S. ...
9
3968
by: lee.chappers | last post by:
How can I make the CodeDom generate the following C# method? protected sealed override void Test() { } I've tried using: domMethod.Attributes = MemberAttributes.Override |...
0
299
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; } ...
17
1802
by: Steven T. Hatton | last post by:
I didn't think this was possible in C++. I don't believe Stroustrup mentions this anywhere in TC++PL(SE). I've never seen it used in code that I can recall. Is this feature widely supported? Is...
3
20815
by: johnmmcparland | last post by:
Hi all, I would like to have a static constant array inside a class definition which would contain the number of days in each month (I am writing a Date class as an exercise). However my...
12
4773
by: PGP | last post by:
I notice that local classes are not supported in C#. Could you please discuss why this is so? Was this a bad coding practice to begin with?
5
2170
by: dancer | last post by:
Using ASP.net 1.1 and VB Is it possible to declare variables in their own subroutine? I had my DIM statements within a sub that worked just fine. I wanted to be able to use them in another...
28
2529
by: cpluslearn | last post by:
Hi, I have a local class inside a function template. I am able to wrap any type in my local class. Is it legal C++? What type of class is Local? Is it a class template or regular class? Thanks...
0
7303
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
7367
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...
0
7471
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...
0
5613
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,...
1
5028
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...
0
4699
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.