示例#1
0
        /// <summary>
        /// Attempts to set the Property called <paramref name="name"/> to the <paramref name="value"/> specified.
        /// <remarks>
        /// Only properties that exist on <see cref="EntityType"/> can be set.
        /// If there is a type mismatch the request will fail.
        /// </remarks>
        /// </summary>
        /// <param name="name">The name of the Property</param>
        /// <param name="value">The new value of the Property</param>
        /// <returns>True if successful</returns>
        public bool TrySetPropertyValue(string name, object value)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }

            if (!_propertiesThatExist.ContainsKey(name))
            {
                return(false);
            }

            PropertyAccessor <TEntityType> cacheHit = _propertiesThatExist[name];
            Type valueType = value != null?value.GetType() : null;

            if (cacheHit.Property.PropertyType != valueType)
            {
                if (!(cacheHit.Property.PropertyType.IsClass && value == null))
                {
                    return(false);
                }
            }

            //.Setter.Invoke(_entity, new object[] { value });
            cacheHit.SetValue(_entity, value);
            _changedProperties.Add(name);
            return(true);
        }
示例#2
0
        /// <inheritdoc/>
        public override bool TrySetPropertyValue(string name, object value)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }

            if (!_propertiesThatExist.ContainsKey(name))
            {
                return(false);
            }

            PropertyAccessor <TEntityType> cacheHit = _propertiesThatExist[name];

            if (value == null && !EdmLibHelpers.IsNullable(cacheHit.Property.PropertyType))
            {
                return(false);
            }

            if (value != null && !cacheHit.Property.PropertyType.IsAssignableFrom(value.GetType()))
            {
                return(false);
            }

            //.Setter.Invoke(_entity, new object[] { value });
            cacheHit.SetValue(_entity, value);
            _changedProperties.Add(name);
            return(true);
        }