CodeDOM, declaring and setting a constant private field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Dan,

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

Hope this helps.
 
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
 
Back
Top