Esempio n. 1
0
        protected override Object CreateValueForExistingPropertyValue(IPropertyValueFactory propertyValueFactory, Object instance,
                                                                      PropertyInfo propertyInfo, Object value)
        {
            if (propertyValueFactory == null)
            {
                throw new ArgumentNullException(nameof(propertyValueFactory));
            }

            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var propertyValue = (IValueAssociation)this.CreateNewPropertyValue(propertyValueFactory, instance, propertyInfo, value);

            return(propertyValue.Value);
        }
Esempio n. 2
0
        protected override PropertyValue CreateNewPropertyValue(IPropertyValueFactory propertyValueFactory, Object instance,
                                                                PropertyInfo propertyInfo, Object value)
        {
            if (propertyValueFactory == null)
            {
                throw new ArgumentNullException(nameof(propertyValueFactory));
            }

            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (propertyInfo == null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(propertyValueFactory.CreatePropertyValue(
                       PropertyValueCreationContext.ForExistingPropertyValue(propertyInfo,
                                                                             new InstanceDescriptorCreationContext(instance, this.instanceRelationStore), value)));
        }
 public PropertyValueInfo(IProperty property, object?value, ValueSource?valueSource, IPropertyValueFactory propertyValueFactory)
 {
     Property             = property;
     Value                = value;
     ValueSource          = valueSource;
     PropertyValueFactory = propertyValueFactory;
 }
        /// <summary>
        /// Creates factory that caches <see cref="IPropertyValue"/> for the same property and value pairs.
        /// </summary>
        /// <param name="propertyValueFactory">Factory.</param>
        /// <param name="propertyComparer">Optional comparer. Default: <see cref="PropertyComparer.ByReferenceComparer"/>.</param>
        /// <param name="maxItemCount">Max item count in cache.</param>
        /// <returns>New cached <see cref="IPropertyValueFactory"/>.</returns>
        public static IPropertyValueFactory Cached(this IPropertyValueFactory propertyValueFactory, IEqualityComparer <IProperty>?propertyComparer = null, int?maxItemCount = null)
        {
            propertyValueFactory.AssertArgumentNotNull(nameof(propertyValueFactory));

            return(new CachedPropertyValueFactory(
                       propertyValueFactory,
                       propertyComparer ?? PropertyComparer.ByReferenceComparer,
                       maxItemCount: maxItemCount));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CachedPropertyValueFactory"/> class.
        /// </summary>
        /// <param name="propertyValueFactory">Real factory.</param>
        /// <param name="propertyComparer">Property comparer.</param>
        /// <param name="maxItemCount">Max item count in cache.</param>
        public CachedPropertyValueFactory(
            IPropertyValueFactory propertyValueFactory,
            IEqualityComparer <IProperty> propertyComparer,
            int?maxItemCount = null)
        {
            propertyValueFactory.AssertArgumentNotNull(nameof(propertyValueFactory));
            propertyComparer.AssertArgumentNotNull(nameof(propertyComparer));

            _propertyValueFactory = propertyValueFactory;

            var propertyValueKeyComparer = new PropertyValueKeyComparer(propertyComparer);

            if (maxItemCount == null)
            {
                // unlimited cache
                _propertyValuesCache = new ConcurrentDictionaryAdapter <PropertyValueInfo, IPropertyValue>(new ConcurrentDictionary <PropertyValueInfo, IPropertyValue>(propertyValueKeyComparer));
            }
            else
            {
                // limited cache
                _propertyValuesCache = new Core.TwoLayerCache <PropertyValueInfo, IPropertyValue>(maxItemCount.Value, propertyValueKeyComparer);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Returns the value of an existing <see cref="PropertyValue"/>.
 /// </summary>
 /// <param name="propertyValueFactory">The <see cref="IPropertyValueFactory"/>.</param>
 /// <param name="instance">The instance of the complex object.</param>
 /// <param name="propertyInfo">The <see cref="PropertyInfo"/> which is intercepted.</param>
 /// <param name="value">The intercepted property value.</param>
 /// <returns>The value of the existing <see cref="PropertyValue"/>.</returns>
 protected abstract Object CreateValueForExistingPropertyValue(IPropertyValueFactory propertyValueFactory, Object instance, PropertyInfo propertyInfo, Object value);
Esempio n. 7
0
 /// <summary>
 /// Creates a new <see cref="PropertyValue"/>.
 /// </summary>
 /// <param name="propertyValueFactory">The <see cref="IPropertyValueFactory"/>.</param>
 /// <param name="instance">The instance of the complex object.</param>
 /// <param name="propertyInfo">The <see cref="PropertyInfo"/> which is intercepted.</param>
 /// <param name="value">The intercepted property value.</param>
 /// <returns>The created <see cref="PropertyValue"/>.</returns>
 protected abstract PropertyValue CreateNewPropertyValue(IPropertyValueFactory propertyValueFactory, Object instance, PropertyInfo propertyInfo, Object value);
Esempio n. 8
0
 protected override Object CreateValueForExistingPropertyValue(
     [CanBeNull] IPropertyValueFactory propertyValueFactory, [CanBeNull] Object instance,
     [CanBeNull] PropertyInfo propertyInfo, [CanBeNull] Object value)
 {
     return(value);
 }