Castle.MonoRail.Framework.Helpers.AbstractHelper.JavascriptOptions C# (CSharp) Method

JavascriptOptions() public static method

Builds a JS associative array based on the specified dictionary instance.

For example: {name: value, other: 'another'}

public static JavascriptOptions ( IDictionary jsOptions ) : string
jsOptions IDictionary The js options.
return string
		public static string JavascriptOptions(IDictionary jsOptions)
		{
			if (jsOptions == null || jsOptions.Count == 0)
			{
				return "{}";
			}

			StringBuilder sb = new StringBuilder(jsOptions.Count * 10);
			sb.Append("{");
			bool comma = false;

			foreach (DictionaryEntry entry in jsOptions)
			{
				if (!comma) comma = true; else sb.Append(", ");

				sb.Append(string.Format("{0}:{1}", entry.Key, entry.Value));
			}

			sb.Append("}");
			return sb.ToString();
		}