469,636 Members | 1,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

How to create a protected method, using CodeDom

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
Nov 16 '05 #1
3 8812

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;

--
Shak
(Houston)
"Tapas" <ta***********@gmail.com> wrote in message
news:1b**************************@posting.google.c om...
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

Nov 16 '05 #2

sorry messed up 3rd answer

3) To set multiple atrributes do this

method.Attributes = MemberAttributes.Static | MemberAttributes.Public;
--
Shak
(Houston)
"Tapas" <ta***********@gmail.com> wrote in message
news:1b**************************@posting.google.c om...
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

Nov 16 '05 #3
sorry messed up 3rd answer

3) To set multiple atrributes do this

method.Attributes = MemberAttributes.Static | MemberAttributes.Public;
--
Shak
(Houston)
"Shakir Hussain" <sh**@nodomain.com> wrote in message
news:uk**************@tk2msftngp13.phx.gbl...

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;

--
Shak
(Houston)
"Tapas" <ta***********@gmail.com> wrote in message
news:1b**************************@posting.google.c om...
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


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Shawn A. Hall | last post: by
1 post views Thread by Mark | last post: by
7 posts views Thread by =?Utf-8?B?YW5kZXJzY2g=?= | last post: by
6 posts views Thread by moondaddy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.