public static string PreProcess <K, V>(this IDictionary <K, V> d, string template, params object[] args) { var d2 = new Dictionary <string, object>(); foreach (var e in d) { d2.Add(e.Key.ToString(), e.Value); } return(ExtendedFormat.Format(template, d2)); }
//public static string Format(this string s, object a1) { return string.Format(s, a1); } //public static string Format(this string s, object a1, object a2) { return string.Format(s, a1, a2); } //public static string Format(this string s, object a1, object a2, object a3) { return string.Format(s, a1, a2, a3); } //public static string Format(this string s, object a1, object a2, object a3, object a4) { return string.Format(s, a1, a2, a3, a4); } //public static string Format(this string s, object a1, object a2, object a3, object a4, object a5) { return string.Format(s, a1, a2, a3, a4, a5); } //public static string Format(this string s, object a1, object a2, object a3, object a4, object a5, object a6) { return string.Format(s, a1, a2, a3, a4, a5, a6); } //public static string Format(this string s, object a1, object a2, object a3, object a4, object a5, object a6, object a7) { return string.Format(s, a1, a2, a3, a4, a5, a6, a7); } //public static string Format(this string s, object a1, object a2, object a3, object a4, object a5, object a6, object a7, object a8) { return string.Format(s, a1, a2, a3, a4, a5, a6, a7, a8); } //public static string Format(this string s, object a1, object a2, object a3, object a4, object a5, object a6, object a7, object a8, object a9) { return string.Format(s, a1, a2, a3, a4, a5, a6, a7, a8, a9); } //public static string Format(this string s, object a1, object a2, object a3, object a4, object a5, object a6, object a7, object a8, object a9, object a10) { return string.Format(s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); } /* * /// <summary> * /// http://extensionmethod.net/csharp/string/FormatString-string * /// Author: Adam Weigert * /// </summary> * /// <param name="FormatString"></param> * /// <param name="arg"></param> * /// <param name="additionalArgs"></param> * /// <returns></returns> * public static string Formataaaaa(this string FormatString, object arg, params object[] additionalArgs) * { * if (additionalArgs == null || additionalArgs.Length == 0) * { * return string.Format(FormatString, arg); * } * else * { * return string.Format(FormatString, new object[] { arg }.Concat(additionalArgs).ToArray()); * } * }*/ /// <summary> /// Replaces the FormatString item in the string with the string representation /// of a corresponding property/field in the object passed. /// </summary> /// <param name="s"></param> /// <param name="poco">Any poco object</param> /// <returns></returns> public static string Template(this string s, object poco) { return(ExtendedFormat.Format(s, ReflectionHelper.GetDictionary(poco))); }