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

GetAttributes() protected method

Generates HTML element attributes string from attributes. key1="value1" key2
string.Empty is returned if attributes is null or empty.

If for some DictionaryEntry.Key DictionaryEntry.Value is null or string.Empty only attribute name is appended to the string.

protected GetAttributes ( IDictionary attributes ) : string
attributes IDictionary The attributes for the element.
return string
		protected string GetAttributes(IDictionary attributes)
		{
			if (attributes == null || attributes.Count == 0) return string.Empty;

			StringBuilder contents = new StringBuilder();

			foreach(DictionaryEntry entry in attributes)
			{
				if (entry.Value == null || entry.Value.ToString() == string.Empty)
				{
					contents.Append(entry.Key);
				}
				else
				{
					contents.AppendFormat("{0}=\"{1}\"", entry.Key, entry.Value);
				}
				contents.Append(' ');
			}

			return contents.ToString();
		}