Ejemplo n.º 1
0
        /// <summary>
        /// Traverses through the provided resource and returns the
        /// value of the relationship on the other side of a through type
        /// (e.g. Articles.ArticleTags.Tag).
        /// </summary>
        public override object GetValue(object resource)
        {
            IEnumerable throughResources = (IEnumerable)ThroughProperty.GetValue(resource) ?? Array.Empty <object>();

            IEnumerable <object> rightResources = throughResources
                                                  .Cast <object>()
                                                  .Select(rightResource => RightProperty.GetValue(rightResource));

            return(rightResources.CopyToTypedCollection(Property.PropertyType));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Traverses through the provided entity and returns the
        /// value of the relationship on the other side of a join entity
        /// (e.g. Articles.ArticleTags.Tag).
        /// </summary>
        public override object GetValue(object entity)
        {
            IEnumerable joinEntities = (IEnumerable)ThroughProperty.GetValue(entity) ?? Array.Empty <object>();

            IEnumerable <object> rightEntities = joinEntities
                                                 .Cast <object>()
                                                 .Select(rightEntity => RightProperty.GetValue(rightEntity));

            return(rightEntities.CopyToTypedCollection(PropertyInfo.PropertyType));
        }
        /// <summary>
        /// Traverses through the provided resource and returns 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 object GetValue(object resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            IEnumerable throughResources = (IEnumerable)ThroughProperty.GetValue(resource) ?? Array.Empty <object>();

            IEnumerable <object> rightResources = throughResources
                                                  .Cast <object>()
                                                  .Select(rightResource => RightProperty.GetValue(rightResource));

            return(TypeHelper.CopyToTypedCollection(rightResources, Property.PropertyType));
        }
        /// <summary>
        /// Traverses through the provided resource and returns 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 object GetValue(object resource)
        {
            ArgumentGuard.NotNull(resource, nameof(resource));

            var throughEntity = ThroughProperty.GetValue(resource);

            if (throughEntity == null)
            {
                return(null);
            }

            IEnumerable <object> rightResources = ((IEnumerable)throughEntity)
                                                  .Cast <object>()
                                                  .Select(rightResource => RightProperty.GetValue(rightResource));

            return(TypeHelper.CopyToTypedCollection(rightResources, Property.PropertyType));
        }
        /// <summary>
        /// Traverses the through the provided entity and returns the
        /// value of the relationship on the other side of a join entity
        /// (e.g. Articles.ArticleTags.Tag).
        /// </summary>
        public override object GetValue(object entity)
        {
            var throughNavigationProperty = entity.GetType()
                                            .GetProperties()
                                            .SingleOrDefault(p => string.Equals(p.Name, InternalThroughName, StringComparison.OrdinalIgnoreCase));

            var throughEntities = throughNavigationProperty.GetValue(entity);

            if (throughEntities == null)
            {
                // return an empty list for the right-type of the property.
                return(TypeHelper.CreateListFor(RightType));
            }

            // the right entities are included on the navigation/through entities. Extract and return them.
            var rightEntities = new List <IIdentifiable>();

            foreach (var rightEntity in (IList)throughEntities)
            {
                rightEntities.Add((IIdentifiable)RightProperty.GetValue(rightEntity));
            }

            return(rightEntities.Cast(RightType));
        }