Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Varying a Property's get/set Accessibility

It is a common occurrence wherein you may want to publicly expose a property's getter but internally restrict the setter. (The last refactoring challenge had a good use for this.)  I regularly see people provide a publicly exposed property - with only a getter - and then add an internally available method for setting that property. Alternatively, as long as you're only "tightening" access, you can simply pre-append the appropriate access keyword in front of the get/set, accordingly. For example:

In the above code, the getter is publicly available while the setter is only internally available to the assembly in which it's defined. You can also use protected, private and logical combinations, if needed.


Posted 02-15-2007 4:55 PM by Billy McCafferty
Filed under:



Michal Grzegorzewski wrote re: Varying a Property's get/set Accessibility
on 02-16-2007 11:03 AM

I would say it's just a naming convention which shows me as a client of your code your intent. It's a kind of agreement between you - provider of this property, and me - the user. When I see 'private', 'internal', etc. I read it that way: 'If you use this method/property/whatever you may get some unpredictible results, so be careful'. It's not a restriction - using DynamicMethod along with ILGenerator.Emit (or by CreateDelegate) we've got dynamic access with almost the same performance as when using direct calls - so, why not use dynamic access? Using tools such as TypeWrapper ( it's even simpler.

awesome linkbuilding site wrote re: Varying a Property's get/set Accessibility
on 10-01-2013 7:40 AM

ptMaub Very neat blog post.Really thank you!

crorkz matz wrote re: Varying a Property's get/set Accessibility
on 08-06-2014 6:45 AM

90SwQ6 Awesome article.Really thank you! Great.

untcqw wrote re: Varying a Property's get/set Accessibility
on 01-17-2015 7:52 PM


daniel craig wrote re: Varying a Property's get/set Accessibility
on 03-02-2015 11:23 AM

Rojp49 Good write-up, I am normal visitor of one's website, maintain up the nice operate, and It's going to be a regular visitor for a lengthy time.

crorkzz wrote re: Varying a Property's get/set Accessibility
on 04-08-2015 7:50 PM

lOALfC Hi my friend! I want to say that this article is amazing, nice written and include approximately all significant infos. I'd like to see more posts like this.

make me feel wrote re: Varying a Property's get/set Accessibility
on 10-14-2016 11:28 AM

OeArA6 Would you be desirous about exchanging links?

Add a Comment

Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)