First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

How many times did you need a property to be read-only for the users of your API, but also you needed that property to be populated by your own data access layer?

It happened to me many times, and I usually solved that problem accessing directly the underlying field changing its visibility from private to internal or protected.

But what if you want to access everything as a property and don't want to hook directly to the field?
You need to be able to specify for the setter a different visibility for the getter.

Here is how:

        private int _id;

        public int Id
            get { return _id; }
            internal set {  _id = value; }

That's a feature of C# I like a lot, and that allows a lot of flexibility.

Just have to remember that the setter visibility modifier must be more restricted than the general one.

UPDATE: This feature is available only with .NET 2.0 (Thank Bill for pointing it out)

posted on Monday, February 26, 2007 5:59 PM

Comments on this entry:

# re: Fine tune your properties with accessors

Left by Bill Pierce at 2/27/2007 3:40 AM

Just wanted to say that feature only became available with .Net 2.0.

# re: Fine tune your properties with accessors

Left by Simone at 2/27/2007 9:43 AM

Thank you Bill... I'll add a note on the post

# re: Fine tune your properties with accessors

Left by spencer at 7/4/2007 10:28 AM

How do i add friends on fine tune?

Comments have been closed on this topic.