/// <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()); }
public static object ToObject(IPhpConvertible value) => value.ToClass();
public static PhpArray ToArray(IPhpConvertible value) => value.ToArray();
/// <summary> /// Converts to boolean according to PHP. /// </summary> public static bool ToBoolean(IPhpConvertible value) => value != null && value.ToBoolean();
public static string ToString(IPhpConvertible value, Context ctx) => value.ToStringOrThrow(ctx);