Пример #1
0
        protected virtual Func <PomonaContext, PomonaResponse> ResolveGetCollectionProperty(ResourcePropertyRoute route,
                                                                                            ResourceProperty property,
                                                                                            ResourceType resourceItemType)
        {
            if (this.capabilityResolver.PropertyIsMapped(property.PropertyInfo) || property.GetPropertyFormula() != null)
            {
                return
                    (pr =>
                {
                    // Check existance of parent here, cannot differentiate between an empty collection and not found.
                    var parent = pr.Node.Parent;
                    if (parent.Route.IsSingle)
                    {
                        if (!parent.Exists)
                        {
                            throw new ResourceNotFoundException("Resource not found.");
                        }
                    }

                    return new PomonaResponse(
                        parent
                        .Query()
                        .OfTypeIfRequired(pr.Node.Route.InputType)
                        .SelectManyEx(x => x.Apply(property.CreateGetterExpression))
                        .WrapActionResult(defaultPageSize: property.ExposedAsRepository ? (int?)null : int.MaxValue));
                });
            }
            else
            {
                return
                    (pr =>
                {
                    var parentNode = pr.Node.Parent;
                    if (parentNode.Route.IsSingle)
                    {
                        return new PomonaResponse(((IEnumerable)property.GetValue(parentNode.Get())).AsQueryable());
                    }
                    return new PomonaResponse(
                        pr.Node.Parent
                        .Query()
                        .OfTypeIfRequired(pr.Node.Route.InputType)
                        .ToListDetectType()
                        .AsQueryable()
                        .SelectManyEx(x => x.Apply(property.CreateGetterExpression))
                        .WrapActionResult(defaultPageSize: property.ExposedAsRepository ? (int?)null : int.MaxValue));
                });
            }
        }
        private void LoadDisplayName()
        {
            _DisplayName = null;

            if (ResourceType != null)
            {
                PropertyInfo ResourceProperty;

                ResourceProperty = ResourceType.GetProperty(Name);
                if (ResourceProperty != null)
                {
                    object Value;

                    Value = ResourceProperty.GetValue(null);
                    if (Value != null)
                    {
                        _DisplayName = Value.ToString();
                    }
                }
            }
        }