using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Reflection; using System.Text; using System.Web; namespace MonoTests.Common { class MyHttpRequestWrapper : HttpRequestBase { Dictionary propertyValues = new Dictionary (); public override string AppRelativeCurrentExecutionFilePath { get { string value; if (!GetProperty ("AppRelativeCurrentExecutionFilePath", out value)) return base.AppRelativeCurrentExecutionFilePath; return value; } } public override string PathInfo { get { string value; if (!GetProperty ("PathInfo", out value)) return base.PathInfo; return value; } } public override NameValueCollection QueryString { get { NameValueCollection value; if (!GetProperty ("QueryString", out value)) return base.QueryString; return value; } } bool GetProperty (string name, out T value) { if (String.IsNullOrEmpty (name)) throw new ArgumentNullException ("name"); value = default (T); object v; if (propertyValues.TryGetValue (name, out v)) { if (v == null) return true; if (typeof (T).IsAssignableFrom (v.GetType ())) { value = (T) v; return true; } throw new InvalidOperationException ("Invalid value type. Expected '" + typeof (T) + "' and got '" + v.GetType () + "'"); } return false; } public void SetProperty (string name, object value) { if (String.IsNullOrEmpty (name)) return; if (propertyValues.ContainsKey (name)) propertyValues[name] = value; else propertyValues.Add (name, value); } } }