How to create a protected method, using CodeDom

T

Tapas

Hi,

Generating a .cs file using CodeDom. It generates the class fine.
But i have few queries about class generation.

1. How to create a protected member?
By default it generates a private method. To make it static say, I do
something like this -
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "TestMethod";
method.Attributes = MemberAttributes.Static;
How make Protected ? There is no attribute called 'Protected' in the
class MemberAttributes !!!!

2. When set the attribute of the method to MemberAttributes.Public
....it generates a method "public virtual". I don't want a virtual in
there. How do I do it?

3. How do I set multiple attrubutes to a method like "public static" ?

Regards
Tapas
 
S

Shakir Hussain

1) To create protected member , use enum

MemberAttributes.Family

2) If you dont want virtual keyword after public, pass first parameter as
null in the CodeFieldReferenceExpression

CodeFieldReferenceExpression cfr = new CodeFieldReferenceExpression(null,
blah);

3) To set multiple atrributes do this

method.Attributes = MemberAttributes.Static | method.Attributes =
MemberAttributes.Public;
 
S

Shakir Hussain

sorry messed up 3rd answer

3) To set multiple atrributes do this

method.Attributes = MemberAttributes.Static | MemberAttributes.Public;
 
S

Shakir Hussain

sorry messed up 3rd answer

3) To set multiple atrributes do this

method.Attributes = MemberAttributes.Static | MemberAttributes.Public;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top