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 if (atts_hash.ContainsKey (key))
62 throw new HttpException ("Tag contains duplicated '" + key +
64 atts_hash.Add (key, value);
71 public ICollection Keys
73 get { return (got_hashed ? atts_hash.Keys : keys); }
76 public ICollection Values
78 get { return (got_hashed ? atts_hash.Values : values); }
81 private int CaseInsensitiveSearch (string key)
83 // Hope not to have many attributes when the tag is not a server tag...
84 for (int i = 0; i < keys.Count; i++){
85 if (0 == String.Compare ((string) keys [i], key, true))
91 public object this [object key]
95 return atts_hash [key];
97 int idx = CaseInsensitiveSearch ((string) key);
106 atts_hash [key] = value;
108 int idx = CaseInsensitiveSearch ((string) key);
116 get { return (got_hashed ? atts_hash.Count : keys.Count);}
119 public bool IsDataBound (string att)
121 if (att == null || !got_hashed)
124 return (att.StartsWith ("<%#") && att.EndsWith ("%>"));
127 public Hashtable GetDictionary (string key)
132 if (tmp_hash == null)
133 tmp_hash = new Hashtable (CaseInsensitiveHashCodeProvider.Default,
134 CaseInsensitiveComparer.Default);
137 for (int i = keys.Count - 1; i >= 0; i--)
138 if (key == null || String.Compare (key, (string) keys [i], true) == 0)
139 tmp_hash [keys [i]] = values [i];
144 public override string ToString ()
146 StringBuilder result = new StringBuilder ();
148 foreach (string key in Keys){
150 value = this [key] as string;
152 result.AppendFormat ("=\"{0}\"", value);
157 if (result.Length > 0 && result [result.Length - 1] == ' ')
160 return result.ToString ();