Beispiel #1
0
        /// <summary>
        /// Creates a boxed helper containing a delegate that will check any of the properties that implement IChangeTracking if they have changed
        /// and a delegate that will accept changes for those properties.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static ChangeTrackingHelper <object> CreateBoxedHelper(object item)
        {
            var type  = item.GetType();
            var cache = BoxedCache;

            ChangeTrackingHelper <object> helper;

            if (cache.TryGetValue(type, out helper))
            {
                return(helper);
            }

            var properties    = GetRelevantProperties(type);
            var hasChanges    = BoxedHasChangesFor(type, properties);
            var acceptChanges = BoxedAcceptChangesFor(type, properties);

            var changeTrackingHelper = new ChangeTrackingHelper <object>(hasChanges, acceptChanges);

            cache.Add(type, changeTrackingHelper);

            return(changeTrackingHelper);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a helper containing a typed delegate that will check any of the properties that implement IChangeTracking if they have changed
        /// and a delegate that will accept changes for those properties.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static ChangeTrackingHelper <T> CreateHelper <T>(T item)
        {
            var type  = item.GetType();
            var cache = Cache;

            object helper;

            if (cache.TryGetValue(type, out helper))
            {
                return((ChangeTrackingHelper <T>)helper);
            }


            var properties    = GetRelevantProperties(type);
            var hasChanges    = HasChangesFor <T>(type, properties);
            var acceptChanges = AcceptChangesFor <T>(type, properties);

            var changeTrackingHelper = new ChangeTrackingHelper <T>(hasChanges, acceptChanges);

            cache.Add(type, changeTrackingHelper);

            return(changeTrackingHelper);
        }