public static object SafeConvert(this ITypeConverter converter, string value) { try { if (converter != null && value.HasValue() && converter.CanConvertFrom(typeof(string))) { return converter.ConvertFrom(value); } } catch (Exception exc) { exc.Dump(); } return null; }
public static string Convert(this string me, Casing from, Casing to) { string result; if (me.IsNull()) result = null; else if (to == Casing.Raw) result = me; else { System.Text.StringBuilder builder = new System.Text.StringBuilder(); foreach (var c in me.ConvertFrom(from).ConvertTo(to)) builder.Append(c); result = builder.ToString(); // Console.WriteLine(result); } return result; }
public static object ConvertFrom(this ITypeConverter converter, object value) { return converter.ConvertFrom(CultureInfo.InvariantCulture, value); }