471,627 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

CodeDom question for .net 2.0

I am using the CodeDom namespace for generating classes, and would
really like to be able to use the CodeRegionDirective class to generate
regions around code blocks.

The only problem is that is looks like i can generate regions around a
single method or a single statement (using StartDirective) property, is
there any way to out a code region around a collection of statements, or
methods ?

any help would be appreciated..

TIA
Dec 14 '05 #1
7 2604
Ashish,

From what I can tell, you need to place two CodeRegionDirectives in your
code, one for the start, and one for the end. So, you find the method where
you want to place the region start, and add the CodeRegionDirective to the
StartDirectives collection.

You then go to the other element of code where you want to place the
region end, and then add the CodeRegionDirective to the EndDirectives
collection.

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

"Ashish" <as*****@thisisjunk.com> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
I am using the CodeDom namespace for generating classes, and would really
like to be able to use the CodeRegionDirective class to generate regions
around code blocks.

The only problem is that is looks like i can generate regions around a
single method or a single statement (using StartDirective) property, is
there any way to out a code region around a collection of statements, or
methods ?

any help would be appreciated..

TIA

Dec 14 '05 #2
Nicholas,

Thanks for the answer,
here is the code fargment ...

CodeTypeDeclaration ctd = new CodeTypeDeclaration();

ctd.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start,
"members"));
ctd.Members.AddRange(this.GetMemberFields());
ctd.StartDirectives.Add(new
CodeRegionDirective(CodeRegionMode.End,string.Empt y));
but code generated by GetMemberFields is not places in the output :(

Thanks



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

From what I can tell, you need to place two CodeRegionDirectives in your
code, one for the start, and one for the end. So, you find the method where
you want to place the region start, and add the CodeRegionDirective to the
StartDirectives collection.

You then go to the other element of code where you want to place the
region end, and then add the CodeRegionDirective to the EndDirectives
collection.

Hope this helps.

Dec 14 '05 #3
Ashish,

Add the last CodeRegionDirective to the EndDirectives.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ashish" <as*****@thisisjunk.com> wrote in message
news:uY**************@TK2MSFTNGP11.phx.gbl...
Nicholas,

Thanks for the answer,
here is the code fargment ...

CodeTypeDeclaration ctd = new CodeTypeDeclaration();

ctd.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start,
"members"));
ctd.Members.AddRange(this.GetMemberFields());
ctd.StartDirectives.Add(new
CodeRegionDirective(CodeRegionMode.End,string.Empt y));
but code generated by GetMemberFields is not places in the output :(

Thanks



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

From what I can tell, you need to place two CodeRegionDirectives in
your code, one for the start, and one for the end. So, you find the
method where you want to place the region start, and add the
CodeRegionDirective to the StartDirectives collection.

You then go to the other element of code where you want to place the
region end, and then add the CodeRegionDirective to the EndDirectives
collection.

Hope this helps.


Dec 14 '05 #4
Nicholas

thanks for pointing that out

i did that, but it adds the regions at the start of the whole class code
instead of just the members :(

for example the generated code looks like

#region members
public clas blah
{
// this is where i want it to start
private int mUId;
.......


}

#endregion

, any other clues ?

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

Add the last CodeRegionDirective to the EndDirectives.

Dec 14 '05 #5
Ashish,

The CodeMemberField class has StartDirectives and EndDirectives
properties which you can attach code directives to. Why not just attach
them to the one that corresponds to the mUId field?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ashish" <as*****@thisisjunk.com> wrote in message
news:ul**************@TK2MSFTNGP15.phx.gbl...
Nicholas

thanks for pointing that out

i did that, but it adds the regions at the start of the whole class code
instead of just the members :(

for example the generated code looks like

#region members
public clas blah
{
// this is where i want it to start
private int mUId;
......


}

#endregion

, any other clues ?

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

Add the last CodeRegionDirective to the EndDirectives.


Dec 14 '05 #6
Nicholas,

well that would surround each member declaration with a region, and i
want to all the member declarations under one region, or there would be
too many regions to deal with .... , seems like this should be do able..

thanks

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

The CodeMemberField class has StartDirectives and EndDirectives
properties which you can attach code directives to. Why not just attach
them to the one that corresponds to the mUId field?

Dec 14 '05 #7
Ashish,

Right, so on the first member in the region, add the directive to the
StartDirectives. In the last member in the region, add the directive to the
EndDirectives.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ashish" <as*****@thisisjunk.com> wrote in message
news:uX**************@TK2MSFTNGP14.phx.gbl...
Nicholas,

well that would surround each member declaration with a region, and i want
to all the member declarations under one region, or there would be too
many regions to deal with .... , seems like this should be do able..

thanks

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

The CodeMemberField class has StartDirectives and EndDirectives
properties which you can attach code directives to. Why not just attach
them to the one that corresponds to the mUId field?


Dec 15 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ron Bullman | last post: by
2 posts views Thread by Guillaume | last post: by
1 post views Thread by John Livermore | last post: by
3 posts views Thread by Alexey Lavnikov | last post: by
6 posts views Thread by moondaddy | last post: by
1 post views Thread by =?Utf-8?B?QU1lcmNlcg==?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.