Exemplo n.º 1
0
        private Func <GetStringRequest, string> findConverter(GetStringRequest request)
        {
            if (request.PropertyType.IsNullable())
            {
                if (request.RawValue == null)
                {
                    return(r => string.Empty);
                }

                return(findConverter(request.GetRequestForNullableType()));
            }

            if (request.PropertyType.IsArray)
            {
                if (request.RawValue == null)
                {
                    return(r => string.Empty);
                }

                return(r =>
                {
                    if (r.RawValue == null)
                    {
                        return string.Empty;
                    }

                    return r.RawValue.As <Array>().OfType <object>().Select(GetString).Join(", ");
                });
            }

            StringifierStrategy strategy = _strategies.FirstOrDefault(x => x.Matches(request));

            return(strategy == null ? toString : strategy.StringFunction);
        }
        /// <summary>
        /// Formats the provided value using the accessor accessor metadata and a custom format
        /// </summary>
        /// <param name="formatter">The formatter</param>
        /// <param name="modelType">The type of the model to which the accessor belongs (i.e. Case where the accessor might be on its base class WorkflowItem)</param>
        /// <param name="accessor">The property that holds the given value</param>
        /// <param name="value">The data to format</param>
        /// <param name="format">The custom format specifier</param>
        public static string FormatValue(this IDisplayFormatter formatter, Type modelType, Accessor accessor, object value, string format)
        {
            var request = new GetStringRequest(accessor, value, null)
            {
                Format = format
            };

            return(formatter.GetDisplay(request));
        }
Exemplo n.º 3
0
 public bool Equals(GetStringRequest other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.OwnerType, OwnerType) && Equals(other.Property, Property) && Equals(other.RawValue, RawValue) && Equals(other.Format, Format));
 }
Exemplo n.º 4
0
        public string GetString(GetStringRequest request)
        {
            if (request == null || request.RawValue == null || (request.RawValue as String) == string.Empty)
            {
                return(string.Empty);
            }
            PropertyOverrideStrategy propertyOverride = _overrides.FirstOrDefault(o => o.Matches(request.Property));

            if (propertyOverride != null)
            {
                return(propertyOverride.StringFunction(request));
            }

            return(findConverter(request)(request));
        }
Exemplo n.º 5
0
 private static string toString(GetStringRequest value)
 {
     return(value.RawValue == null ? string.Empty : value.RawValue.ToString());
 }
Exemplo n.º 6
0
        public string GetDisplayForValue(Accessor accessor, object rawValue)
        {
            var request = new GetStringRequest(accessor, rawValue, _locator);

            return(_stringifier.GetString(request));
        }
Exemplo n.º 7
0
        public string GetDisplay(Accessor accessor, object target)
        {
            var request = new GetStringRequest(accessor, target, _locator);

            return(_stringifier.GetString(request));
        }
Exemplo n.º 8
0
 public string GetDisplay(GetStringRequest request)
 {
     request.Locator = _locator;
     return(_stringifier.GetString(request));
 }