// Convert an object value into a string. public static String FromObject(Object Value) { if (Value != null) { if (Value is String) { return((String)Value); } #if !ECMA_COMPAT else if (Value is IConvertible) { return(((IConvertible)Value).ToString(null)); } else if (Value is char[]) { return(new String(CharArrayType.FromObject(Value))); } else { throw new InvalidCastException (String.Format(S._("VB_InvalidCast"), Value.GetType(), "String")); } #else else { return(Value.ToString()); } #endif }
public static string FromObject(object Value) { if (Value == null) { return(null); } string str2 = Value as string; if (str2 != null) { return(str2); } IConvertible convertible = Value as IConvertible; if (convertible != null) { switch (convertible.GetTypeCode()) { case TypeCode.Boolean: return(FromBoolean(convertible.ToBoolean(null))); case TypeCode.Char: return(FromChar(convertible.ToChar(null))); case TypeCode.Byte: return(FromByte(convertible.ToByte(null))); case TypeCode.Int16: return(FromShort(convertible.ToInt16(null))); case TypeCode.Int32: return(FromInteger(convertible.ToInt32(null))); case TypeCode.Int64: return(FromLong(convertible.ToInt64(null))); case TypeCode.Single: return(FromSingle(convertible.ToSingle(null))); case TypeCode.Double: return(FromDouble(convertible.ToDouble(null))); case TypeCode.Decimal: return(FromDecimal(convertible.ToDecimal(null))); case TypeCode.DateTime: return(FromDate(convertible.ToDateTime(null))); case TypeCode.String: return(convertible.ToString(null)); } } else { char[] chArray = Value as char[]; if ((chArray != null) && (chArray.Rank == 1)) { return(new string(CharArrayType.FromObject(Value))); } } throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromTo", new string[] { Utils.VBFriendlyName(Value), "String" })); }