/// <summary> /// Throw a multiexception. /// If this multi exception is empty then no action is taken. If it /// contains a any exceptions then this /// </summary> /// /// <exception cref="MultiException"></exception> public void IfExceptionThrowMulti() { if (LazyList.Size(nested) > 0) { throw this; } }
/// <summary> /// Get value as string. /// Single valued items are converted to a string with the ToString() /// object method. Multi valued entries are converted to a comma separated /// List. No quoting of commas within values is performed. /// </summary> /// <param name="name">The entry key</param> /// <returns>string value</returns> public string GetString(K name) { object l = _map.ContainsKey(name) ? _map[name] : null; switch (LazyList.Size(l)) { case 0: return(null); case 1: object o = LazyList.Get(l, 0); return(o == null ? null : o.ToString()); default: { StringBuilder values = new StringBuilder(128); for (int i = 0; i < LazyList.Size(l); i++) { object e = LazyList.Get(l, i); if (e != null) { if (values.Length > 0) { values.Append(','); } values.Append(e.ToString()); } } return(values.ToString()); } } }
/// <summary> /// Throw a ApplicationException exception. /// If this multi exception is empty then no action is taken. If it /// contains a single error or ApplicationException that is thrown, otherwise the this /// multi exception is thrown, wrapped in a ApplicationException. /// </summary> /// /// <exception cref="SystemException">If this exception contains only 1 SystemException</exception> /// <exception cref="ApplicationException"> /// If this exception contains only 1 Exception but it is not a SystemException /// If contains more than 1 Exceptions of any type, then multi-exception is wrapped as an ApplicationException /// </exception> public void IfExceptionApplicationException() { switch (LazyList.Size(nested)) { case 0: break; case 1: Exception exception = (Exception)LazyList.Get(nested, 0); if (exception is SystemException) { throw (SystemException)exception; } else if (exception is ApplicationException) { throw (ApplicationException)exception; } else { throw new ApplicationException(exception.Message, exception); } default: throw new ApplicationException("Mulitple Exceptions", this); } }
public override string ToString() { if (LazyList.Size(nested) > 0) { return("NJetty.Util.Util.MultiException" + LazyList.GetList(nested)); } return("NJetty.Util.Util.MultiException[]"); }
/// <summary> /// Get a value from a multiple value. /// If the value is not a multivalue, then index 0 retrieves the /// value or null. /// </summary> /// <param name="name">The entry key.</param> /// <param name="i">Index of element to get.</param> /// <returns>Unmodifieable List of values.</returns> public object GetValue(K name, int i) { object l = _map.ContainsKey(name) ? _map[name] : null; if (i == 0 && LazyList.Size(l) == 0) { return(null); } return(LazyList.Get(l, i)); }
/// <summary> /// Add and Exception to the List of Multiple Exceptions /// </summary> /// <param name="e"></param> public void Add(Exception e) { if (e is MultiException) { MultiException me = (MultiException)e; for (int i = 0; i < LazyList.Size(me.nested); i++) { nested = LazyList.Add(nested, LazyList.Get(me.nested, i)); } } else { nested = LazyList.Add(nested, e); } }
public new bool TryGetValue(K key, out object value) { object l = _map.TryGetValue(key, out value); switch (LazyList.Size(l)) { case 0: return(false); case 1: value = LazyList.Get(l, 0); return(true); default: value = LazyList.GetList(l, true); return(true); } }
/// <summary> /// Remove value. /// </summary> /// <param name="name">The entry key</param> /// <param name="value">The entry value</param> /// <returns>true if it was removed</returns> public bool RemoveValue(K name, object value) { object lo = _map.ContainsKey(name) ? _map[name] : null; object ln = lo; int s = LazyList.Size(lo); if (s > 0) { ln = LazyList.Remove(lo, value); if (ln == null) { _map.Remove(name); } else { _map.Add(name, ln); } } return(LazyList.Size(ln) != s); }
public new object this[K name] { get { object l = _map.ContainsKey(name) ? _map[name] : null; switch (LazyList.Size(l)) { case 0: return(null); case 1: object o = LazyList.Get(l, 0); return(o); default: return(LazyList.GetList(l, true)); } } set { Add(name, value); } }
/// <summary> /// Throw a multiexception. /// If this multi exception is empty then no action is taken. If it /// contains a single exception that is thrown, otherwise the this /// multi exception is thrown. /// </summary> /// /// <exception cref="Exception"></exception> /// <exception cref="SystemException"></exception> /// <exception cref="MultiException">throws this instance, If there are more that one Exception</exception> public void IfExceptionThrow() { switch (LazyList.Size(nested)) { case 0: break; case 1: Exception exception = (Exception)LazyList.Get(nested, 0); if (exception is SystemException) { throw (SystemException)exception; } if (exception is Exception) { throw (Exception)exception; } throw this; default: throw this; } }
/// <summary> /// Encode Hashtable with % encoding. /// </summary> /// <param name="map">multimap values to encode</param> /// <param name="charset">Characterset Encoding</param> /// <param name="equalsForNullValue">if True, then an '=' is always used, even /// for parameters without a value. e.g. "blah?a=&b=&c=". /// </param> /// <returns>Encoded string Value</returns> public static string Encode(MultiMap <string> map, string charset, bool equalsForNullValue) { if (charset == null) { charset = StringUtil.__UTF8; } StringBuilder result = new StringBuilder(128); bool first = true; foreach (string key in map.Keys) { if (!first) { result.Append('&'); } object list = map[key]; int s = LazyList.Size(list); if (s == 0) { result.Append(EncodeString(key, charset)); if (equalsForNullValue) { result.Append('='); } } else { for (int i = 0; i < s; i++) { if (i > 0) { result.Append('&'); } object val = LazyList.Get(list, i); result.Append(EncodeString(key, charset)); if (val != null) { string str = val.ToString(); if (str.Length > 0) { result.Append('='); result.Append(EncodeString(str, charset)); } else if (equalsForNullValue) { result.Append('='); } } else if (equalsForNullValue) { result.Append('='); } } } first = false; } return(result.ToString()); }