Hi Andrew.Do you can add a wiki page, on NH-Forge (How To section), with the
implementation of your Observable bag and how use it ?
You can even upload sources in your page (in nh-forge) and link the wiki to
it.

For "usage" note take a look to <typedef> features (example available
in NHibernate.Test.UserCollection.Parameterized)

Really thanks for your contribution and for the right spirit.
Fabio Maulo.

2008/12/7 Andrew C <[EMAIL PROTECTED]>

>
> HappyNomad:
>
> I got ObservableBag working with the new trunk by extending
> PersistantGenericBag and replacing the InnerBag with an
> ObservableCollection. See below:
>
>    [Serializable, DebuggerTypeProxy(typeof
> (NHibernate.DebugHelpers.CollectionProxy<>))]
>    public class PersistentObservableBag<T> : PersistentGenericBag<T>,
> INotifyCollectionChanged
>    {
>
>        public PersistentObservableBag(ISessionImplementor session)
>            : base(session)
>        {
>        }
>
>        public PersistentObservableBag(ISessionImplementor session,
> ICollection<T> coll)
>            : base(session, coll)
>        {
>            INotifyCollectionChanged collection = coll as
> INotifyCollectionChanged;
>            if (collection != null)
>            {
>                collection.CollectionChanged += new
> NotifyCollectionChangedEventHandler(OnCollectionChanged);
>            }
>        }
>
>        public override void BeforeInitialize(ICollectionPersister
> persister, int anticipatedSize)
>        {
>            this.InternalBag = (IList<T>)
> persister.CollectionType.Instantiate(anticipatedSize);
>            INotifyCollectionChanged collection = base.InternalBag as
> INotifyCollectionChanged;
>            if (collection != null)
>            {
>                collection.CollectionChanged += new
> NotifyCollectionChangedEventHandler(OnCollectionChanged);
>            }
>        }
>
>        protected void OnCollectionChanged(object sender,
> NotifyCollectionChangedEventArgs e)
>        {
>            if (CollectionChanged != null)
>                CollectionChanged(this, e);
>        }
>
>        public event NotifyCollectionChangedEventHandler
> CollectionChanged;
>
>    }
>
>    public class ObservableBagType<T> : IUserCollectionType
>    {
>        #region IUserCollectionType Members
>
>        public bool Contains(object collection, object entity)
>        {
>            return ((IList<T>)collection).Contains((T)entity);
>        }
>
>        public IEnumerable GetElements(object collection)
>        {
>            return (IEnumerable)collection;
>        }
>
>        public object IndexOf(object collection, object entity)
>        {
>            return ((IList<T>)collection).IndexOf((T)entity);
>        }
>
>        public object ReplaceElements(object original, object target,
> ICollectionPersister persister, object owner, IDictionary copyCache,
> ISessionImplementor session)
>        {
>            IList<T> result = (IList<T>)target;
>            result.Clear();
>            foreach (object item in ((IEnumerable)original))
>                result.Add((T)item);
>            return result;
>        }
>
>        // return an instance of the inner collection type
>        public object Instantiate(int anticipatedSize)
>        {
>            return new ObservableCollection<T>();
>        }
>
>        public IPersistentCollection Instantiate(ISessionImplementor
> session, ICollectionPersister persister)
>        {
>            return new PersistentObservableBag<T>(session);
>        }
>
>        public IPersistentCollection Wrap(ISessionImplementor session,
> object collection)
>        {
>            return new PersistentObservableBag<T>(session,
> (ICollection<T>)collection);
>        }
>
>        #endregion
>    }
>



-- 
Fabio Maulo

Reply via email to