Exemplo n.º 1
0
 /// <summary>
 /// Initializes the delegates that are used to check and accept changes for properties.
 /// </summary>
 public void PrepareChangeTracking()
 {
     if (_helper == null)
     {
         _helper = ChangeTrackingFactory.CreateExtendedBoxedHelper(this);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an extended boxed helper containing a delegate that will check any of the properties that implement IChangeTracking if they have changed,
        /// a delegate that will accept changes for those properties
        /// and a method call to make the properties stop listening for changes.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static ExtendedChangeTrackingHelper <object> CreateExtendedBoxedHelper(object item)
        {
            var type  = item.GetType();
            var cache = ExtendedBoxedCache;

            ExtendedChangeTrackingHelper <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 stopChangeTracking = BoxedStopChangeTrackingFor(type, properties);

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

            cache.Add(type, changeTrackingHelper);

            return(changeTrackingHelper);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an extended helper containing a delegate that will check any of the properties that implement IChangeTracking if they have changed,
        /// a delegate that will accept changes for those properties
        /// and a method call to make the properties stop listening for changes.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static ExtendedChangeTrackingHelper <T> CreateExtendedHelper <T>(T item)
        {
            var type  = item.GetType();
            var cache = ExtendedCache;

            object helper;

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

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

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

            cache.Add(type, changeTrackingHelper);

            return(changeTrackingHelper);
        }