Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

CodeDom question for .net 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ashish - 14 Dec 2005 17:08 GMT
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
Nicholas Paldino [.NET/C# MVP] - 14 Dec 2005 17:31 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I am using the CodeDom namespace for generating classes, and would really
>like to be able to use the CodeRegionDirective class to generate regions
[quoted text clipped - 8 lines]
>
> TIA
Ashish - 14 Dec 2005 18:25 GMT
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.Empty));

but code generated by GetMemberFields is not places in the output :(

Thanks

> Ashish,
>
[quoted text clipped - 8 lines]
>
>     Hope this helps.
Nicholas Paldino [.NET/C# MVP] - 14 Dec 2005 18:32 GMT
Ashish,

   Add the last CodeRegionDirective to the EndDirectives.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Nicholas,
>
[quoted text clipped - 25 lines]
>>
>>     Hope this helps.
Ashish - 14 Dec 2005 19:53 GMT
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 ?

> Ashish,
>
>     Add the last CodeRegionDirective to the EndDirectives.
Nicholas Paldino [.NET/C# MVP] - 14 Dec 2005 20:09 GMT
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?

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Nicholas
>
[quoted text clipped - 22 lines]
>>
>>     Add the last CodeRegionDirective to the EndDirectives.
Ashish - 14 Dec 2005 21:22 GMT
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

> 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] - 15 Dec 2005 21:31 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Nicholas,
>
[quoted text clipped - 9 lines]
>> properties which you can attach code directives to.  Why not just attach
>> them to the one that corresponds to the mUId field?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.