using System; using System.Collections; using System.Collections.Generic; namespace OSHttpServer { /// /// Returns item either from a form or a query string (checks them in that order) /// public class HttpParam : IHttpInput { /// Representation of a non-initialized HttpParam public static readonly HttpParam Empty = new HttpParam(HttpInput.Empty, HttpInput.Empty); private IHttpInput m_form; private IHttpInput m_query; private List _items = new List(); /// Initialises the class to hold a value either from a post request or a querystring request public HttpParam(IHttpInput form, IHttpInput query) { m_form = form; m_query = query; } #region IHttpInput Members /// /// The add method is not availible for HttpParam /// since HttpParam checks both Request.Form and Request.QueryString /// /// name identifying the value /// value to add /// [Obsolete("Not implemented for HttpParam")] public void Add(string name, string value) { throw new NotImplementedException(); } /// /// Checks whether the form or querystring has the specified value /// /// Name, case sensitive /// true if found; otherwise false. public bool Contains(string name) { return m_form.Contains(name) || m_query.Contains(name); } /// /// Fetch an item from the form or querystring (in that order). /// /// /// Item if found; otherwise HttpInputItem.EmptyLanguageNode public HttpInputItem this[string name] { get { if (m_form[name] != HttpInputItem.Empty) return m_form[name]; else return m_query[name]; } } #endregion internal void SetQueryString(HttpInput query) { m_query = query; } internal void SetForm(HttpInput form) { m_form = form; } /// ///Returns an enumerator that iterates through the collection. /// /// /// ///A that can be used to iterate through the collection. /// ///1 IEnumerator IEnumerable.GetEnumerator() { List items = new List(m_query); items.AddRange(m_form); return items.GetEnumerator(); } #region IEnumerable Members /// ///Returns an enumerator that iterates through a collection. /// /// /// ///An object that can be used to iterate through the collection. /// ///2 public IEnumerator GetEnumerator() { List items = new List(m_query); items.AddRange(m_form); return items.GetEnumerator(); } #endregion } }