471,627 Members | 1,681 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.

Nested properties

Hi everyone,

I've a Configuration class with almost 200 read only properties.
This class makes available configuration data to my whole application.

I would like to group realted properties together.
The idea is to access the properties this way
configuration.Database.Server.IPAddress
instead of
configuration.Database_Server_IPAddress

The above is only a sample but should get you the idea.

At first glance I should create other classes (in the example above I would
need at least the Database and Server classes) and nest them inside my
Configuration class.
But this approach requires a lot of work.
1. I have to create dozen of classes
2. It's difficult to make the classes read-only: they would be read only
also for the container class!
3. The point 2 above can be addresses at construction time: I could create
constructors which setup the read only properties, but again it's a lot of
work to do. If my nested properties has a 2 level depth, I should assign the
values at least 3 times (and that's 600 assignments for 200 properties!)...

Any idea?

Kind regards,
Corrado
Jan 12 '06 #1
1 1793
Corrado,

With .NET 2.0, you can create properties where the get and set accessors
with different access levels. So, you could set your get property as
public, and your set as internal, like so:

public int MyValue
{
get
{
return myValue;
}
internal set
{
myValue = value;
}
}

You would have the set be internal so you can set from within your
assembly.
You would still have to create separate classes to create groupings, but
that's a good thing. After all, you are trying to encapsulate
functionality.

Hope this helps.

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

"Corrado Labinaz @ngi.it>" <corradolab<no-s-pam> wrote in message
news:e7**************@TK2MSFTNGP10.phx.gbl...
Hi everyone,

I've a Configuration class with almost 200 read only properties.
This class makes available configuration data to my whole application.

I would like to group realted properties together.
The idea is to access the properties this way
configuration.Database.Server.IPAddress
instead of
configuration.Database_Server_IPAddress

The above is only a sample but should get you the idea.

At first glance I should create other classes (in the example above I
would need at least the Database and Server classes) and nest them inside
my Configuration class.
But this approach requires a lot of work.
1. I have to create dozen of classes
2. It's difficult to make the classes read-only: they would be read only
also for the container class!
3. The point 2 above can be addresses at construction time: I could create
constructors which setup the read only properties, but again it's a lot of
work to do. If my nested properties has a 2 level depth, I should assign
the values at least 3 times (and that's 600 assignments for 200
properties!)...

Any idea?

Kind regards,
Corrado

Jan 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by nobody | last post: by
1 post views Thread by Edward Diener | last post: by
8 posts views Thread by Robert W. | last post: by
4 posts views Thread by Steve Franks | last post: by
reply views Thread by GBR | last post: by
6 posts views Thread by Marc Hoeijmans | last post: by
1 post views Thread by Morten Fagermoen | last post: by
4 posts views Thread by =?Utf-8?B?Qnlyb24=?= | last post: by
4 posts views Thread by =?Utf-8?B?YmlsbCB0aWU=?= | last post: by
1 post views Thread by p.tilhoo | 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.