コード例 #1
0
        /// <summary>
        /// Replaces a wrapped reference list, detaching contained items if needed, and confiures the wrapper to wrap a
        /// replacement list.
        /// </summary>
        /// <param name='wrapperToOverwrite'>
        /// The wrapper instance to overwrite.
        /// </param>
        /// <param name='replacement'>
        /// The replacement source list.
        /// </param>
        /// <param name='referenceProperty'>
        /// An expression indicating a property upon the contained type.
        /// </param>
        /// <param name='referenceItem'>
        /// The reference item to be stored in the <paramref name="referenceProperty"/>.
        /// </param>
        /// <typeparam name='T'>
        /// The type of item contained within the list.
        /// </typeparam>
        /// <remarks>
        /// <para>
        /// See the documentation of this type for detailled information on how this works and what it does.
        /// </para>
        /// </remarks>
        public static void Replace <T>(ref ISet <T> wrapperToOverwrite,
                                       ISet <T> replacement,
                                       Expression <Func <T, object> > referenceProperty,
                                       object referenceItem) where T : class
        {
            if (replacement == null)
            {
                throw new ArgumentNullException("replacement");
            }

            EventBoundSetWrapper <T> typedList = wrapperToOverwrite as EventBoundSetWrapper <T>;

            if (typedList != null)
            {
                typedList.DetachAll();
            }

            PropertyInfo propInfo = Reflect.Property(referenceProperty);

            foreach (T item in replacement)
            {
                propInfo.SetValue(item, referenceItem, null);
            }

            wrapperToOverwrite = GetOrInit(replacement, referenceProperty, referenceItem);
        }
コード例 #2
0
        /// <summary>
        /// Clones the current instance.
        /// </summary>
        public object Clone()
        {
            Iesi.Collections.Generic.ISet <T> clonedWrappedSet;
            clonedWrappedSet = (Iesi.Collections.Generic.ISet <T>)base.WrappedCollection.Clone();
            EventBoundSetWrapper <T> clonedWrapper = new EventBoundSetWrapper <T>(clonedWrappedSet);

            clonedWrapper.BeforeAdd    = this.BeforeAdd;
            clonedWrapper.AfterAdd     = this.AfterAdd;
            clonedWrapper.BeforeRemove = this.BeforeRemove;
            clonedWrapper.AfterRemove  = this.AfterRemove;

            return(clonedWrapper);
        }
コード例 #3
0
        /// <summary>
        /// Gets a wrapped reference list, initialising it if required.
        /// </summary>
        /// <returns>
        /// A generic IList, with added addition and removal handlers.
        /// </returns>
        /// <param name='wrapper'>
        /// The list wrapper instance to use.
        /// </param>
        /// <param name='original'>
        /// The original/source list.
        /// </param>
        /// <param name='referenceProperty'>
        /// An expression indicating a property upon the contained type.
        /// </param>
        /// <param name='referenceItem'>
        /// The reference item to be stored in the <paramref name="referenceProperty"/>.
        /// </param>
        /// <typeparam name='T'>
        /// The type of item contained within the list.
        /// </typeparam>
        /// <remarks>
        /// <para>
        /// See the documentation of this type for detailled information on how this works and what it does.
        /// </para>
        /// </remarks>
        public static ISet <T> GetOrInit <T>(ref ISet <T> wrapper,
                                             ref ISet <T> original,
                                             Expression <Func <T, object> > referenceProperty,
                                             object referenceItem) where T : class
        {
            EventBoundSetWrapper <T> typedList = wrapper as EventBoundSetWrapper <T>;

            if (typedList == null || !typedList.IsWrapping(original))
            {
                original = original ?? new HashedSet <T>();
                wrapper  = GetOrInit(original, referenceProperty, referenceItem);
            }

            return(wrapper);
        }
コード例 #4
0
        /// <summary>
        /// Initialises and returns a new list wrapper, wrapping the given <paramref name="original"/> collection.
        /// </summary>
        /// <returns>
        /// A generic IList, with added addition and removal handlers.
        /// </returns>
        /// <param name='original'>
        /// The original/source list.
        /// </param>
        /// <param name='referenceProperty'>
        /// An expression indicating a property upon the contained type.
        /// </param>
        /// <param name='referenceItem'>
        /// The reference item to be stored in the <paramref name="referenceProperty"/>.
        /// </param>
        /// <typeparam name='T'>
        /// The type of item contained within the list.
        /// </typeparam>
        private static EventBoundSetWrapper <T> GetOrInit <T>(ISet <T> original,
                                                              Expression <Func <T, object> > referenceProperty,
                                                              object referenceItem) where T : class
        {
            if (original == null)
            {
                throw new ArgumentNullException("original");
            }

            EventBoundSetWrapper <T> output = original as EventBoundSetWrapper <T>;

            if (output == null)
            {
                PropertyInfo propInfo = Reflect.Property(referenceProperty);

                output = original.WrapWithBeforeActions((list, item) => BeforeAdd(list, item, propInfo, referenceItem),
                                                        (list, item) => BeforeRemove(list, item, propInfo));
            }

            return(output);
        }