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

CodeDOM, declaring and setting a constant private field

Using CodeDOM, is there a way to declare and set a private field.

Something like:

private const int tableConstant = 10;

//Provide the type and variable name
CodeMemberField mymemberfield = new CodeMemberField(fieldType,fieldName);
mymemberfield.Attributes = MemberAttributes.Private;
//Add the member to the class
newClass.Members.Add(mymemberfield);

Thanks,

Dan H.
Nov 17 '05 #1
3 6755
Dan,

Once you create the CodeMemberField, you can set the InitExpression
property to the expression you want to initialize the field.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<Da********@nospam.nospam> wrote in message
news:OS****************@TK2MSFTNGP15.phx.gbl...
Using CodeDOM, is there a way to declare and set a private field.

Something like:

private const int tableConstant = 10;

//Provide the type and variable name
CodeMemberField mymemberfield = new CodeMemberField(fieldType,fieldName);
mymemberfield.Attributes = MemberAttributes.Private;
//Add the member to the class
newClass.Members.Add(mymemberfield);

Thanks,

Dan H.

Nov 17 '05 #2
HI Dan

Try this

CodeMemberField cmf = new CodeMemberField(typeof(System.Int32
),"tableConstant") ;
cmf.Attributes = MemberAttributes.Const | MemberAttributes.Private ;
cmf.InitExpression = new CodePrimitiveExpression(10);

hope it helps

regards

Ronnie
Nov 17 '05 #3
Thx! Worked perfectly!

Dan
"Ronnie Edgar" <Ro*********@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
HI Dan

Try this

CodeMemberField cmf = new CodeMemberField(typeof(System.Int32
),"tableConstant") ;
cmf.Attributes = MemberAttributes.Const | MemberAttributes.Private ;
cmf.InitExpression = new CodePrimitiveExpression(10);

hope it helps

regards

Ronnie

Nov 17 '05 #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?...
4
by: Chuck Bowling | last post by:
I am using CodeDOM to generate source files. The classes being generated have a const string member. This member is referenced in an abstract base class but declared in the inheriting class. I...
4
by: Vagmi Mudumbai | last post by:
Hi, I am working on CodeDOM to generate a more usable class to serialize and deserialize WXS files. I have hit the wall at a pretty early stage. :-( I am attempting to change the member public...
7
by: Iain Mcleod | last post by:
Hi This must be an often encountered problem. I want to declare an abstract class or an interface with nothing but several static constants so that I can use polymorphism when I call each of them...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: CHU Run-min | last post by:
The following code was written by me. It is used for evaluating constant expressions. I think it is good. Any criticism? namespace Churunmin.HelloWorld {
0
by: Michael Jenck | last post by:
Hi All, I have been playing with the codedom and can't get it to output for option compare Binary with a CodeCompileUnit. I have searched the web and Don't now if it's possible. If it's not...
4
by: Johs | last post by:
I have this in a file called bas.h: #ifndef BAS_H_ #define BAS_H_ class GeoObj { public: void draw() const; int getNum();
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.