473,806 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.D atabase.Server. IPAddress
instead of
configuration.D atabase_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 1875
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.co m

"Corrado Labinaz @ngi.it>" <corradolab<n o-s-pam> wrote in message
news:e7******** ******@TK2MSFTN GP10.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.D atabase.Server. IPAddress
instead of
configuration.D atabase_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
1499
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 them so you access them like MyObject.Commands.blah1, MyObject.Commands.blah2, etc... So some of the methods are grouped under "Commands". My first thought was a nested class, but how would the methods in the nested Commands object (easily)...
1
1373
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 are serialized. Should my nested class be: 1) A struct, with my component class holding a value variable for it. 2) A class, with my component class holding a reference variable for it. If the latter, does the nested class need to be derived...
8
16926
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. This works fine if all of the properties are at the top (root level) of the model but I'd like to keep them in nested classes to organize them better. So, for example, part of my data model looks like this (simplified) : public class MainClass
4
2471
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 nested master page between the content page and the top level master? For example, assume the very top level master is called CompanyWide.master. And the nested master page is called DepartmentA.master, which inherits from CompanyWide master. ...
0
962
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
3116
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
3345
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 groups? Sub GetGroupMembers(ByVal ggmGroup As String, ByRef ggmMembers As
4
7148
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 Building._Name to Building._BName in case the duplicate name was the issue, but that didn't help. Is there a native way to serialize nested objects, or will I have to write my own? public class LocationCell
4
1688
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
5420
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 objects. Basically my object called layercontrol will contain and array of layergroup which in turn contains map layer objects. The layergroup and layer object should be just like any object of properties and
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.