예제 #1
0
        private bool TrySetNestedResourceInternal(string name, object deltaNestedResource)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }

            if (!_updatableProperties.Contains(name))
            {
                return(false);
            }

            if (_deltaNestedResources.ContainsKey(name))
            {
                // Ignore duplicated nested resource.
                return(false);
            }

            PropertyAccessor <TStructuralType> cacheHit = _allProperties[name];
            // Get the Delta<{NestedResourceType}>._instance using Reflection.
            FieldInfo field = deltaNestedResource.GetType().GetField("_instance", BindingFlags.NonPublic | BindingFlags.Instance);

            Contract.Assert(field != null, "field != null");
            cacheHit.SetValue(_instance, field.GetValue(deltaNestedResource));

            // Add the nested resource in the hierarchy.
            // Note: We shouldn't add the structural properties to the <code>_changedProperties</code>, which
            // is used for keeping track of changed non-structural properties at current level.
            _deltaNestedResources[name] = deltaNestedResource;

            return(true);
        }
예제 #2
0
        private bool TrySetPropertyValueInternal(string name, object value)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }

            if (!_updatableProperties.Contains(name))
            {
                return(false);
            }

            PropertyAccessor <TStructuralType> cacheHit = _allProperties[name];

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

            Type propertyType = cacheHit.Property.PropertyType;

            if (value != null && !TypeHelper.IsCollection(propertyType) && !propertyType.IsAssignableFrom(value.GetType()))
            {
                return(false);
            }

            cacheHit.SetValue(_instance, value);
            _changedProperties.Add(name);
            return(true);
        }
예제 #3
0
        /// <inheritdoc/>
        public override bool TrySetPropertyValue(string name, object value)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }

            if (_dynamicDictionaryPropertyinfo != null)
            {
                // Dynamic property can have the same name as the dynamic property dictionary.
                if (name == _dynamicDictionaryPropertyinfo.Name ||
                    !_allProperties.ContainsKey(name))
                {
                    if (_dynamicDictionaryCache == null)
                    {
                        _dynamicDictionaryCache =
                            GetDynamicPropertyDictionary(_dynamicDictionaryPropertyinfo, _instance, create: true);
                    }

                    _dynamicDictionaryCache[name] = value;
                    _changedDynamicProperties.Add(name);
                    return(true);
                }
            }

            if (!_updatableProperties.Contains(name))
            {
                return(false);
            }

            PropertyAccessor <TStructuralType> cacheHit = _allProperties[name];

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

            Type propertyType = cacheHit.Property.PropertyType;

            if (value != null && !TypeHelper.IsCollection(propertyType) && !propertyType.IsAssignableFrom(value.GetType()))
            {
                return(false);
            }

            cacheHit.SetValue(_instance, value);
            _changedProperties.Add(name);
            return(true);
        }