示例#1
0
        /// <summary>
        /// Use an IValueProjector strategy to override how the projection is performed for a complex object
        /// </summary>
        /// <param name="projector"></param>
        /// <returns></returns>
        public AccessorProjection <T, TValue> ProjectWith(IValueProjector <TValue> projector)
        {
            _inner = new ExternallyFormattedValueProjector <T, TValue>(_accessor, projector)
            {
                AttributeName = Name()
            };

            return(this);
        }
示例#2
0
        public AccessorProjection(Accessor accessor)
        {
            _accessor = accessor;

            if (typeof(TValue).CanBeCastTo <IProjectMyself>())
            {
                _inner = typeof(SelfProjectingValueProjector <,>)
                         .CloseAndBuildAs <ISingleValueProjection <T> >(accessor, typeof(T), typeof(TValue));
            }
            else
            {
                _inner = new SingleValueProjection <T>(_accessor.Name, c => c.Values.ValueFor(_accessor));
            }
        }
示例#3
0
        /// <summary>
        /// Writes the Url that accesses the value of this accessor as the input
        /// </summary>
        /// <param name="urlFinder"></param>
        /// <returns></returns>
        public AccessorProjection <T, TValue> WriteUrlFor(Func <IUrlRegistry, TValue, string> urlFinder)
        {
            _inner = new SingleValueProjection <T>(_inner.AttributeName, context =>
            {
                var raw = context.Values.ValueFor(_accessor);
                if (raw == null)
                {
                    return(string.Empty);
                }

                return(urlFinder(context.Urls, (TValue)raw));
            });

            return(this);
        }
示例#4
0
        /// <summary>
        /// Use a Func to transform the property value to another value in the projection
        /// </summary>
        /// <param name="formatting"></param>
        /// <returns></returns>
        public AccessorProjection <T, TValue> FormattedBy(Func <TValue, object> formatting)
        {
            _inner = new SingleValueProjection <T>(_inner.AttributeName, context =>
            {
                var raw = context.Values.ValueFor(_accessor);
                if (raw == null)
                {
                    return(null);
                }

                return(formatting((TValue)raw));
            });

            return(this);
        }
示例#5
0
        /// <summary>
        /// Applies the IDisplayFormatter formatting to this individual
        /// </summary>
        /// <returns></returns>
        public AccessorProjection <T, TValue> Formatted()
        {
            _inner = new SingleValueProjection <T>(_inner.AttributeName, context => context.FormattedValueOf(_accessor));

            return(this);
        }