473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 1855
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: nobody | last post by:
I just tried to do something and realized I'm not sure of the proper (if there *IS* a proper) way to do it. I'm designing a class with a lot a methods/properties. I would like to group some of...
1
by: Edward Diener | last post by:
I want to create a nested class within my component class. The nested class will have public properties. Naturally I want those properties to be serialized just as those properties of my component...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
4
by: Steve Franks | last post by:
I have this cool nested master page scenario working great. However what is the correct way to be able to access a strongly typed property at the top level master from a content page that has a...
0
by: GBR | last post by:
Hi Guys, I have been boggling over this for the past few days. I have a class like this: Class A Property Name as String Property ID as Integer Property Address as B End Class
6
by: Marc Hoeijmans | last post by:
How is it possible to us a property from a nested class. Example: namespace MyApp { public class MaxLength { public class Project {
1
by: Morten Fagermoen | last post by:
Hi! I have the function below that return all users in a group, but this code does not work if there are nested groups. Can anyone tell me what to change to also get the users in the nested...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
4
by: =?Utf-8?B?YmlsbCB0aWU=?= | last post by:
I'm perusing a class that seems to utilize a nested class for private fields. In a nutshell, it looks as follows: public class Foo { public Property1 { get/set Bar.field1 }
1
by: p.tilhoo | last post by:
Hello there, I am a programmer mostly using c# and just started using Javascript. I am trying to use prototype to declare and use an object and having difficulties in coding for nested...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.