Andy Smith's Blog

Page.RegisterStartupScript('Andy', 'MetaBuilders_WebControls_GainKnowledge();');

partial nested classes

"Partial classes" is on of the new features of v2 that, while I totally get why Microsoft wanted to add it, I didn't really see any use of them beyond the vstudio code gen world.
"Nested classes" was one of the features of v1 that, while I completely understood the theoretical point of them, I had a HECK of a time coming up with any possible senario where it would actually be useful and the Right Decision.

And now, within the last week, I've ran across 2 instances where the combination of both of these features made the project better and more managable.

I'll only talk about one of them because only one is my code :)

I'm working on a control on v2 to get a feel for various new technologies we get to play with, like callbacks and new designer possibilities. One such new designer feature is the Smart Tags that pop open next to controls which give you quick access to various actions on the control. I'm using the smart tag to let you show or hide areas of the control, so you can see them as you set the various styles.

Implementing these smart tag actions isn't quite as simple as it could be for the simple cases, but I can see that it's quite powerful. So, getting back on topic, the implementation requires a custom Designer for the control, an ActionList class which handles the selection of the smart tag actions, and a TypeConverter class that supplies the list of actions shown in the smart tag. Neither the ActionList nor the TypeConverter class are useful outside of the Designer and the ActionList needs to access members of the Designer which really should be private. Therefore, they are both prime candidates for being nested classes.

However, having three classes in one code file can get tedioius with the scrolling and such. And that is where partial classes come in. Before partial classes I would have just set them as internal to avoid the problem, but that is more exposure than they require. So with partial classes, I put each nested class in its own file, with the parents' "partial class" declaration becoming an extended namespace of sorts.

So with the combination of these two features, I now have the classes having the least amount of exposure they require while still getting all the file management features I would normally have with seperate internal classes.

So ya, call me a convert.

Comments

IT Consultant NY said:

Great explanation, we were lot confused about where this class was to be used.

# September 15, 2008 3:42 AM

joe said:

Hi,

   The author did the great job. The idea of the person is good.

joe

<a href="http://business.bizoppjunction.com">Home Based Business</a>

# February 26, 2009 5:00 AM

P bass said:

I am genuinely not as well familiar with this subject but I do like to pay a visit to weblogs for layout suggestions and interesting topics. You really expanded upon a subject that I generally don't care much about and produced it incredibly interesting. That is a awesome webpage that I'll take be aware of. I by now bookmarked it for future reference. Cheers

--------------------------------------------

my website is  

http://coffeecups.mobi

Also welcome you!

# November 22, 2010 6:13 AM

essential ipad accessories said:

Bad times make a good man.

-----------------------------------

# December 19, 2010 11:00 AM

ipad reviews said:

The man who has made up his mind to win will never say "impossible ".

-----------------------------------

# December 24, 2010 11:54 AM

ipad accessories said:

-----------------------------------------------------------

their is usually a dilemma in the 1st location.

# January 7, 2011 9:41 PM

camera reviews said:

Hey very great weblog!Man Lovely . Astounding.I will bookmark your website and take the feeds also.

--------------------------------------------------------------------  

I have a <a href="onlytopreviews.com/">computer monitor reviews</a> Website,i love him.Mania !You are welcome to look!

# January 16, 2011 6:55 PM

IT Consultant said:

I never really use them other when the environment generates them. Classes should be complete and if interfaces are preffered

# February 1, 2011 8:31 PM

shaiya gold said:

nice work.better.with you.plz keep it away.

# April 22, 2011 10:31 AM

weblogs.asp.net said:

424465.. Very nice :)

# May 17, 2011 10:01 PM

Website Consultant said:

Partial classes is a great feature of .net

# June 16, 2011 4:19 PM

Eveline Sword said:

Hi there, just became aware about your weblog by means of Google, and discovered that it really is really informative. I am going to watch out for brussels. I'll appreciate should you continue this in future. A great deal of persons might be benefited from your writing. Cheers!

# July 1, 2011 5:46 AM

Hershel Rabassa said:

I've even thought of this question in the past, but haven't accessed a conclusion, Sigh ~

# July 5, 2011 7:42 AM

net lights said:

I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful page!

Please contact us if you need our products.Welcome to patronize our Website!     Led Web-Stores

# April 1, 2013 11:30 PM

Mayray said:

Nice insight there.

University of Nigeria

http://unn.edu.ng

# May 8, 2013 5:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)