예제 #1
0
 /// <summary>
 /// We remove the property with the info passed in from the transition.
 /// </summary>
 internal void RemoveProperty(TransitionedPropertyInfo info)
 {
     lock (_lock)
     {
         TransitionedProperties.Remove(info);
     }
 }
예제 #2
0
        /// <summary>
        /// Adds a property that should be animated as part of this transition.
        /// </summary>
        public Transition Add(object target, string propertyName, object destinationValue)
        {
            // We get the property info...
            var targetType   = target.GetType();
            var propertyInfo = targetType.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                throw new InvalidOperationException($"Object: {target} does not have the property: {propertyName}");
            }

            // We check that we support the property type...
            var propertyType = propertyInfo.PropertyType;

            if (!_mapManagedTypes.ContainsKey(propertyType))
            {
                throw new InvalidOperationException($"Transition does not handle properties of type: {propertyType}");
            }

            // We can only transition properties that are both getable and setable...
            if (!propertyInfo.CanRead || !propertyInfo.CanWrite)
            {
                throw new InvalidOperationException($"Property is not both getable and setable: {propertyName}");
            }

            var managedType = _mapManagedTypes[propertyType];

            // We can manage this type, so we store the information for the
            // transition of this property...
            var info = new TransitionedPropertyInfo
            {
                EndValue     = destinationValue,
                Target       = target,
                PropertyInfo = propertyInfo,
                ManagedType  = managedType
            };

            lock (_lock)
            {
                TransitionedProperties.Add(info);
            }

            return(this);
        }