protected override object Evaluate (HttpContext ctx, Control control)
{
- if (control == null) return null;
- if (control.Page == null) return null;
+ if (control == null)
+ return null;
+ if (control.Page == null)
+ return null;
if(String.IsNullOrEmpty(ControlID))
throw new ArgumentException ("The ControlID property is not set.");
throw new ArgumentException ("The PropertyName property is not set and the Control identified by the ControlID property is not decorated with a ControlValuePropertyAttribute attribute.");
ControlValuePropertyAttribute attr = (ControlValuePropertyAttribute) attrs [0];
propName = attr.Name;
- }
- PropertyInfo prop = c.GetType ().GetProperty (propName);
- if (prop == null)
- throw new InvalidOperationException ("Property '" + propName + "' not found in type '" + c.GetType () + "'.");
+ }
- return prop.GetValue (c, null);
+ return DataBinder.Eval (c, propName);
}
[WebCategoryAttribute ("Control")]
public static object Eval (object container, string expression)
{
- if ((expression == null) || (expression.Length == 0))
+ expression = expression != null ? expression.Trim () : null;
+ if (expression == null || expression.Length == 0)
throw new ArgumentNullException ("expression");
object current = container;
}
Type t = container.GetType ();
+
// MS does not seem to look for any other than "Item"!!!
object [] atts = t.GetCustomAttributes (typeof (DefaultMemberAttribute), false);
if (atts.Length != 1)
- throw new ArgumentException (expr + " indexer not found.");
-
- property = ((DefaultMemberAttribute) atts [0]).MemberName;
+ property = "Item";
+ else
+ property = ((DefaultMemberAttribute) atts [0]).MemberName;
Type [] argTypes = new Type [] { (is_string) ? typeof (string) : typeof (int) };
PropertyInfo prop = t.GetProperty (property, argTypes);
using System;
using System.Collections.Generic;
+using System.Collections.Specialized;
using System.Text;
using NUnit.Framework;
using System.Web;
namespace MonoTests.System.Web.UI.WebControls
{
- public class ControlParameterPoker : ControlParameter
- {
- public ControlParameterPoker (ControlParameter control)
- : base (control)
- {
- }
+ public class ControlParameterPoker : ControlParameter
+ {
+ public ControlParameterPoker (ControlParameter control)
+ : base (control)
+ {
+ }
- public ControlParameterPoker (string name,TypeCode type, string controlID,string propertyName)
- :base(name,type,controlID,propertyName)
- {
- }
+ public ControlParameterPoker (string name,TypeCode type, string controlID,string propertyName)
+ :base(name,type,controlID,propertyName)
+ {
+ }
- public ControlParameterPoker (string name, string controlId, string propertyName)
+ public ControlParameterPoker (string name, string controlId, string propertyName)
: base (name, controlId, propertyName)
- {
- }
+ {
+ }
- public ControlParameterPoker (string name, string controlId)
+ public ControlParameterPoker (string name, string controlId)
: base (name, controlId)
- {
- }
+ {
+ }
- public ControlParameterPoker() // constructor
- {
- TrackViewState ();
- }
-
- public object DoEvaluate (HttpContext context,Control control)
- {
- return base.Evaluate (context,control);
- }
-
- public Parameter DoClone ()
- {
- return base.Clone ();
- }
+ public ControlParameterPoker() // constructor
+ {
+ TrackViewState ();
+ }
+
+ public object DoEvaluate (HttpContext context,Control control)
+ {
+ return base.Evaluate (context,control);
+ }
+
+ public Parameter DoClone ()
+ {
+ return base.Clone ();
+ }
- public object SaveState ()
- {
- return SaveViewState ();
- }
+ public object SaveState ()
+ {
+ return SaveViewState ();
+ }
- public void LoadState (object o)
- {
- LoadViewState (o);
- }
+ public void LoadState (object o)
+ {
+ LoadViewState (o);
+ }
- public StateBag StateBag
- {
- get { return base.ViewState; }
- }
+ public StateBag StateBag
+ {
+ get { return base.ViewState; }
+ }
- }
+ }
- [TestFixture]
+ class TestControl : Control
+ {
+ DataKey _values;
+
+ public DataKey Values {
+ get { return _values; }
+ }
+
+ public TestControl (DataKey values)
+ {
+ this._values = values;
+ }
+ }
+
+ [TestFixture]
public class ControlParameterTest
{
[Test]
Assert.AreEqual ("TestNewValue", value, "EvaluateValue2");
}
+ [Test]
+ public void ControlParameter_EvaluateComplex ()
+ {
+ ControlParameterPoker ctrlParam = new ControlParameterPoker ("Test", "TestControl1", "Values['one']");
+ Page page = new Page ();
+
+ OrderedDictionary dict = new OrderedDictionary ();
+ dict.Add ("one", "1");
+
+ DataKey values = new DataKey (dict);
+ TestControl test = new TestControl (values);
+ test.ID = "TestControl1";
+ page.Controls.Add (test);
+ string value = ctrlParam.DoEvaluate (HttpContext.Current, test) as string;
+ Assert.AreEqual ("1", value, "#1");
+ }
+
[Test]
[ExpectedException (typeof (ArgumentException))]
public void EvaluateArgumemtException ()