Ejemplo n.º 1
0
        /// <summary>
        /// Converts option's value to string to be displayed.
        /// </summary>
        /// <param name="value">The value of the option.</param>
        /// <returns>String representation of the option's value.</returns>
        private static string OptionValueToString(object value)
        {
            // lists:
            IList list = value as IList;

            if (list != null)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] != null)
                    {
                        if (i > 0)
                        {
                            sb.Append("; ");
                        }
                        sb.Append(list[i].ToString());
                    }
                }
                return(sb.ToString());
            }

            // convertible:
            IPhpConvertible conv = value as IPhpConvertible;

            if (conv != null)
            {
                return(conv.ToString());
            }

            Encoding encoding = value as Encoding;

            if (encoding != null)
            {
                return(encoding.WebName);
            }

            // others:
            return((value == null) ? String.Empty : value.ToString());
        }
Ejemplo n.º 2
0
 public static object ToObject(IPhpConvertible value) => value.ToClass();
Ejemplo n.º 3
0
 public static PhpArray ToArray(IPhpConvertible value) => value.ToArray();
Ejemplo n.º 4
0
 /// <summary>
 /// Converts to boolean according to PHP.
 /// </summary>
 public static bool ToBoolean(IPhpConvertible value) => value != null && value.ToBoolean();
Ejemplo n.º 5
0
 public static string ToString(IPhpConvertible value, Context ctx) => value.ToStringOrThrow(ctx);