Пример #1
0
        internal static bool IsItemContainedInAllSourceItems <TItemSource>(
            IViewModel selectionVM,
            TItemSource sourceItem
            )
        {
            IEnumerable <TItemSource> allSourceItems = GetAllSourceItems <TItemSource>(selectionVM);

            return(allSourceItems.Contains(sourceItem, ReferenceEqualityComparer <TItemSource> .CreateSmartComparer()));
        }
        public WrapperCollectionAccessorBehavior(
            bool shouldCacheSourceCollection,
            IEqualityComparer <TItemSource> reusabilitySourceComparer = null
            )
        {
            _shouldCacheSourceCollection = shouldCacheSourceCollection;

            _reusabilitySourceComparer =
                reusabilitySourceComparer ??
                ReferenceEqualityComparer <TItemSource> .CreateSmartComparer();
        }
        private Dictionary <TItemSource, TItemVM> GetCache(IBehaviorContext context)
        {
            Dictionary <TItemSource, TItemVM> cache;

            if (!context.FieldValues.TryGetValue(_cache, out cache))
            {
                // Reference equality because:
                //   (1) If the source objects are reloaded in a new NHibernate session,
                //       the are equal to the old object and thus item VMs would be mistakenly
                //       reused.
                //   (2) If two items of the all source items collection are equal, only one
                //       view model would be created for both.
                cache = new Dictionary <TItemSource, TItemVM>(ReferenceEqualityComparer <TItemSource> .CreateSmartComparer());
                context.FieldValues.SetValue(_cache, cache);
            }

            return(cache);
        }