Array property implementation

Array property implementation

Old forum URL: forums.lhotka.net/forums/t/4137.aspx


Ruudjah posted on Wednesday, January 09, 2008

Hi,

I am wondering what the "best" methods is for implementing an array (list of values).I could not fin this in the documentation, and I thought of several ways.

First, you can define a completely new class which derives from EditableChildList or ReadOnlyList using a value type of string. But isnt this too much overhead?

Second, you can use a private variable List. Then expose it using a property getter. Does the framework support this?

Third, declare a private variable of string[] and expose it using a property getter. This has two drawbacks: each time an array is getted, it is copied instead of referenced. Also, databinding can throw exceptions when not initialized.

JoeFallon1 replied on Wednesday, January 09, 2008

I use a private variable List(Of String) and then expose it using a property getter.

Joe


 

KKoteles replied on Wednesday, January 09, 2008

Ruudjah,

Look in Rocky's book for NameValueListBase.  I think that is the object you are looking for.  It provides an implementation of ReadOnlyBindingList which supports read-only name-value pairs. 

If you need more than a simple name-value pair, then I recommend you implement a ReadOnlyList of ReadOnlyBase objects (yes, it has more overhead - but you have the ablility to better define the properties of your object).  I'm not sure I'd go with your option two or three - at least not if you are trying to work with CSLA and keep its rich feature set.

Ken

Ruudjah replied on Wednesday, January 09, 2008

Thanks for sharing your thoughts.

But the datatype I am looking for, is not a name/value pair. It is an unordened list of values. Hence, the NameValueListBase does not apply here, I don't have names to store. Specifically, one property is a list of ID's referring to data which is out of the scope of the domain.

Keeping the CSLA featureset is the goal. The relevance of my question is because of this goal. In other words, to keep the CSLA features, do I need to implement solution 1, or is two also sufficient (three is inferior in my eyes)?

I do not need any rules or authorization on the property mentioned. But I do have other properties which are unordened lists which muight behave different (rules & authorization applied).

KKoteles replied on Friday, January 11, 2008

Ruudjah,

I guess it boils down to whether the list of values would constitute an 'object' or not.  If it is actually an object itself, then I would lean toward what I mentioned originally - ReadOnlyList with ReadOnlyBase objects.  However, if the list is merely a property of your object then your option 2 / JoeFallon1's recommendation should work just fine.  Since the list would be a property and not an object, you are not losing any of CSLA's features in anyway.

Sounds like the design choice is yours.  Your core object can even handle the rules / authorization functionality for the property for you (even if the distinction is a little fuzzy about whether what you are really exposing is a 'property' or an object) - although you might need to get a little fancier to make sure it is processed correctly.

Ken

 

Copyright (c) Marimer LLC