/// <summary>
        /// Traverses through the provided resource and sets the value of the relationship on the other side of the through type.
        /// In the example described above, this would be the value of "Articles.ArticleTags.Tag".
        /// </summary>
        public override void SetValue(object resource, object newValue)
        {
            ArgumentGuard.NotNull(resource, nameof(resource));

            base.SetValue(resource, newValue);

            if (newValue == null)
            {
                ThroughProperty.SetValue(resource, null);
            }
            else
            {
                List <object> throughResources = new List <object>();
                foreach (IIdentifiable rightResource in (IEnumerable)newValue)
                {
                    var throughEntity = TypeHelper.CreateInstance(ThroughType);

                    LeftProperty.SetValue(throughEntity, resource);
                    RightProperty.SetValue(throughEntity, rightResource);
                    throughResources.Add(throughEntity);
                }

                var typedCollection = TypeHelper.CopyToTypedCollection(throughResources, ThroughProperty.PropertyType);
                ThroughProperty.SetValue(resource, typedCollection);
            }
        }
        /// <summary>
        /// Sets the value of the property identified by this attribute
        /// </summary>
        /// <param name="entity">The target object</param>
        /// <param name="newValue">The new property value</param>
        public override void SetValue(object entity, object newValue)
        {
            var propertyInfo = entity
                               .GetType()
                               .GetProperty(InternalRelationshipName);

            propertyInfo.SetValue(entity, newValue);

            if (newValue == null)
            {
                ThroughProperty.SetValue(entity, null);
            }
            else
            {
                var throughRelationshipCollection = (IList)Activator.CreateInstance(ThroughProperty.PropertyType);
                ThroughProperty.SetValue(entity, throughRelationshipCollection);

                foreach (IIdentifiable pointer in (IList)newValue)
                {
                    var throughInstance = Activator.CreateInstance(ThroughType);
                    LeftProperty.SetValue(throughInstance, entity);
                    RightProperty.SetValue(throughInstance, pointer);
                    throughRelationshipCollection.Add(throughInstance);
                }
            }
        }
Esempio n. 3
0
 static RandomCanvas()
 {
     LeftProperty.OverrideMetadata(typeof(RandomCanvas), new FrameworkPropertyMetadata(double.NaN, OnPositioningChanged));
     TopProperty.OverrideMetadata(typeof(RandomCanvas), new FrameworkPropertyMetadata(double.NaN, OnPositioningChanged));
     RightProperty.OverrideMetadata(typeof(RandomCanvas), new FrameworkPropertyMetadata(double.NaN, OnPositioningChanged));
     BottomProperty.OverrideMetadata(typeof(RandomCanvas), new FrameworkPropertyMetadata(double.NaN, OnPositioningChanged));
 }
        /// <summary>
        /// Traverses through the provided resource and sets the value of the relationship on the other side of the through type.
        /// In the example described above, this would be the value of "Articles.ArticleTags.Tag".
        /// </summary>
        public override void SetValue(object resource, object newValue, IResourceFactory resourceFactory)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }
            if (resourceFactory == null)
            {
                throw new ArgumentNullException(nameof(resourceFactory));
            }

            base.SetValue(resource, newValue, resourceFactory);

            if (newValue == null)
            {
                ThroughProperty.SetValue(resource, null);
            }
            else
            {
                List <object> throughResources = new List <object>();
                foreach (IIdentifiable identifiable in (IEnumerable)newValue)
                {
                    object throughResource = resourceFactory.CreateInstance(ThroughType);
                    LeftProperty.SetValue(throughResource, resource);
                    RightProperty.SetValue(throughResource, identifiable);
                    throughResources.Add(throughResource);
                }

                var typedCollection = TypeHelper.CopyToTypedCollection(throughResources, ThroughProperty.PropertyType);
                ThroughProperty.SetValue(resource, typedCollection);
            }
        }
Esempio n. 5
0
        /// <inheritdoc />
        public override void SetValue(object entity, object newValue, IResourceFactory resourceFactory)
        {
            base.SetValue(entity, newValue, resourceFactory);

            if (newValue == null)
            {
                ThroughProperty.SetValue(entity, null);
            }
            else
            {
                List <object> joinEntities = new List <object>();
                foreach (IIdentifiable resource in (IEnumerable)newValue)
                {
                    object joinEntity = resourceFactory.CreateInstance(ThroughType);
                    LeftProperty.SetValue(joinEntity, entity);
                    RightProperty.SetValue(joinEntity, resource);
                    joinEntities.Add(joinEntity);
                }

                var typedCollection = joinEntities.CopyToTypedCollection(ThroughProperty.PropertyType);
                ThroughProperty.SetValue(entity, typedCollection);
            }
        }
 set => SetValue(LeftProperty, value);
Esempio n. 7
0
 get => (double)GetValue(LeftProperty); set => SetValue(LeftProperty, value);
Esempio n. 8
0
 set => this.SetValue(LeftProperty, value);
Esempio n. 9
0
 set { SetValue(LeftProperty, value); }