Exemplo n.º 1
0
        public static string ToString(object target, string formatName)
        {
            if (target == null)
            {
                return(String.Empty);
            }

            if (!HasFormatterSpecified(target))
            {
                Func <object, string> customFormatter = ChoGlobalObjectFormatters.GetObjectFormatHandler(target.GetType(), formatName);
                if (customFormatter != null)
                {
                    return(customFormatter(target));
                }
                else
                {
                    ICustomFormatter formatter = ChoFormatProvider.Instance.GetFormat(target.GetType()) as ICustomFormatter;

                    if (formatter != null)
                    {
                        return(formatter.Format(formatName, target, null));
                    }
                    else
                    {
                        return(ToString(target));
                    }
                }
            }
            else
            {
                return(ToString(target));
            }
        }
Exemplo n.º 2
0
        public static string ToString(object target, string formatName)
        {
            if (target == null)
            {
                return(String.Empty);
            }

            if (!HasFormatterSpecified(target))
            {
                Func <object, string> customFormatter = ChoGlobalObjectFormatters.GetObjectFormatHandler(target.GetType(), formatName);
                if (customFormatter != null)
                {
                    return(customFormatter(target));
                }
                else
                {
                    ICustomFormatter formatter = ChoFormatProvider.Instance.GetFormat(target.GetType()) as ICustomFormatter;

                    ICustomFormatter tmpFormatter = formatter;
                    if (ChoApplication.OnObjectFormatterResolve(target.GetType(), out tmpFormatter))
                    {
                        formatter = tmpFormatter;
                    }

                    if (formatter != null)
                    {
                        return(formatter.Format(formatName, target, null));
                    }
                    else if (formatName.IsNullOrWhiteSpace())
                    {
                        return(ToString(target));
                    }
                    else
                    {
                        return(ChoObject.Format(target, formatName));
                    }
                }
            }
            else
            {
                return(ToString(target));
            }
        }