2 // System.Web.Compilation.TagAttributes
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 using System.Collections;
14 namespace System.Web.Compilation
24 public TagAttributes ()
27 keys = new ArrayList ();
28 values = new ArrayList ();
33 atts_hash = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
34 CaseInsensitiveComparer.Default);
35 for (int i = 0; i < keys.Count; i++)
36 atts_hash.Add (keys [i], values [i]);
42 public bool IsRunAtServer ()
47 public void Add (object key, object value)
49 if (key != null && value != null &&
50 0 == String.Compare ((string) key, "runat", true)) {
51 if (0 != String.Compare ((string) value, "server", true))
52 throw new HttpException ("runat attribute must have a 'server' value");
55 return; // ignore duplicate runat="server"
61 value = HttpUtility.HtmlDecode (value.ToString ());
64 if (atts_hash.ContainsKey (key))
65 throw new HttpException ("Tag contains duplicated '" + key +
67 atts_hash.Add (key, value);
74 public ICollection Keys
76 get { return (got_hashed ? atts_hash.Keys : keys); }
79 public ICollection Values
81 get { return (got_hashed ? atts_hash.Values : values); }
84 private int CaseInsensitiveSearch (string key)
86 // Hope not to have many attributes when the tag is not a server tag...
87 for (int i = 0; i < keys.Count; i++){
88 if (0 == String.Compare ((string) keys [i], key, true))
94 public object this [object key]
98 return atts_hash [key];
100 int idx = CaseInsensitiveSearch ((string) key);
109 atts_hash [key] = value;
111 int idx = CaseInsensitiveSearch ((string) key);
119 get { return (got_hashed ? atts_hash.Count : keys.Count);}
122 public bool IsDataBound (string att)
124 if (att == null || !got_hashed)
127 return (att.StartsWith ("<%#") && att.EndsWith ("%>"));
130 public Hashtable GetDictionary (string key)
135 if (tmp_hash == null)
136 tmp_hash = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
137 CaseInsensitiveComparer.Default);
140 for (int i = keys.Count - 1; i >= 0; i--)
141 if (key == null || String.Compare (key, (string) keys [i], true) == 0)
142 tmp_hash [keys [i]] = values [i];
147 public override string ToString ()
149 StringBuilder result = new StringBuilder ();
151 foreach (string key in Keys){
153 value = this [key] as string;
155 result.AppendFormat ("=\"{0}\"", value);
160 if (result.Length > 0 && result [result.Length - 1] == ' ')
163 return result.ToString ();