private PropertyContext GetProperty(NakedObject nakedObject, string propertyName, bool onlyVisible = true)
        {
            if (string.IsNullOrEmpty(propertyName.Trim()))
            {
                throw new BadRequestNOSException();
            }
            string nof2Id = propertyName.ToLower();

            IEnumerable <NakedObjectField> fields = nakedObject.getSpecification().getFields();

            if (onlyVisible)
            {
                fields = fields.Where(p => !p.isHidden() && p.isVisible(nakedObject).isAllowed());
            }

            NakedObjectField property = fields.SingleOrDefault(p => p.getId() == nof2Id);

            if (property == null)
            {
                throw new PropertyResourceNotFoundNOSException(propertyName);
            }

            if (!property.isCollection())
            {
                property.get(nakedObject); // get value so any errors happen inside error mapping code
            }

            return(new PropertyContext {
                Target = nakedObject, Property = property
            });
        }
Пример #2
0
        public IObjectFacade GetValue(IObjectFacade target)
        {
            Naked result = assoc.get((NakedObject)((ObjectFacade)target).NakedObject);

            return(result == null ? null : new ObjectFacade(result, FrameworkFacade));
        }