child structure for readonlylists?

child structure for readonlylists?

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


mtagliaf posted on Monday, July 16, 2007

I'm finally getting to develop a new app in CSLA 2.0 - my 1.x apps were too big to rewrite, so I'm a bit behind the cutting edge here as far as CSLA 2.x goes (not to mention 3.x).

In the "good old days", there was a pattern I often used for ReadOnlyCollections where a structure was defined to hold the list item data.  I liked this pattern b/c these small collections were contained in a single source file, and the structure was a child of the collection class:

class ListOfThingsToBePicked
  inherits ReadonlyCollectionBase

  structure OneThingToBePicked
  end structure

end class.

Does this pattern exist in the CSLA 2.x world?  All the examples of ReadOnlyListBase that I've seen use a second class as their "child" items.

thanks,
matt tag

ajj3085 replied on Monday, July 16, 2007

If all you need is a name value pair, look at NameValueListBase.  Also, you should upgrade to 3.0.  There are some databinding bug fixes (well, code that helps you find your databinding bugs).  You can compile without using any of the .Net 3.0 stuff by defining the NET20 compiler symbol.

JoeFallon1 replied on Monday, July 16, 2007

Matt,

As you know you can use either a Structure or an embedded class. Rocky's examples happen to use the class. I changed from Structures to classes just to stay more consistent with Rocky's style. The advantage to the class is that it also inherits from your base class that sits between CSLA and all your BOs so it has whatever extra properties and methods all your other RO classes have.

The biggest "gotcha" that occurred during the transition was that some old code no longer worked as expected because classes and structures are different when it comes to being Nothing.

e.g. On a page I had something like:

If mData.MyInfo.SomeProperty Is Nothing Then

which worked great for Structures because the structure itself was not Nothing - all of its fields were.

When I switch to embedded classes I had to re-write the code as:

If mData.MyInfo Is Nothing Then

The trouble is that this was not a compile error but a run-time error so it was harder to track down.

Joe

 

mtagliaf replied on Monday, July 16, 2007

thanks, I think I'll switch over to the class-pattern as well.

Also, I'll upgrade to 3.0.  Might as well stay as current as possible!

matt tag

Copyright (c) Marimer LLC