These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Read-only collections
PostPosted: Wed Nov 21, 2007 2:21 pm 
Newbie

Joined: Mon Jun 11, 2007 8:23 am
Posts: 3
Hi all.
Just a note, hope it can be useful to someone.
I am using a bag to map data and wanted only a readonly version to be available to outside objects. To do so, i used the following property:
Code:
public IList<Session> Sessions {
  get { return new ReadOnlyCollection<Session>(sessions); }
  private set {
    sessions = value;
    RegisterSessions();
}
private IList<Session> sessions;


By doing so, at one point, NH made sessions the readonly version of itself... making adding sessions impossible, even for the object itself.

Instead, i made a fully private property for sessions and a separate readonly public property.

This caused me some headache... hope i can save the trouble to someone else.

jacques.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.