2008-10-08 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Wed, 8 Oct 2008 10:31:17 +0000 (10:31 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Wed, 8 Oct 2008 10:31:17 +0000 (10:31 -0000)
* ControlParameter.cs: Evaluate calls DataBinder.Eval to do the
evaluation now. This makes it support complex expressions.

2008-10-08  Marek Habersack  <mhabersack@novell.com>

* DataBinder.cs: in Eval expression needs to be trimmed before
checking whether it's an empty string.
GetIndexedPropertyValue must explicitly look for the "Item"
property, the lack of the DefaultMember attribute on type must not
throw exceptions.

2008-10-08  Marek Habersack  <mhabersack@novell.com>

* ControlParameterTest.cs: added a test for ControlParameter
evaluating a complex property expression.

svn path=/trunk/mcs/; revision=115193

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/ControlParameter.cs
mcs/class/System.Web/System.Web.UI/ChangeLog
mcs/class/System.Web/System.Web.UI/DataBinder.cs
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/Test/System.Web.UI.WebControls/ControlParameterTest.cs

index 1ecc09febeb789607d7a463517c045e6f9499a8e..6aed7e9a5978178419f604eb6e80b7e8c8716858 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-08  Marek Habersack  <mhabersack@novell.com>
+
+       * ControlParameter.cs: Evaluate calls DataBinder.Eval to do the
+       evaluation now. This makes it support complex expressions.
+
 2008-09-30  Sebastien Pouliot  <sebastien@ximian.com> 
 
        * RoleGroupCollection.cs: Fix recursive calls (wrong target)
index 3464b1d6d65df3890ea231ef986bb483d503a17c..c64bb93c9cdab5e5acf7b05494a6f42a36b99b9f 100644 (file)
@@ -74,8 +74,10 @@ namespace System.Web.UI.WebControls {
                
                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.");
@@ -98,12 +100,9 @@ namespace System.Web.UI.WebControls {
                                        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")]
index 0e570127559746558ad6b7d82e9e7fc8069a52db..430b30df5402a1f2f5cc57f0bd2cc674d3f2e366 100644 (file)
@@ -1,3 +1,11 @@
+2008-10-08  Marek Habersack  <mhabersack@novell.com>
+
+       * DataBinder.cs: in Eval expression needs to be trimmed before
+       checking whether it's an empty string.
+       GetIndexedPropertyValue must explicitly look for the "Item"
+       property, the lack of the DefaultMember attribute on type must not
+       throw exceptions.
+
 2008-10-03  Marek Habersack  <mhabersack@novell.com>
 
        * TemplateParser.cs: make sure the generated class name is a valid
index 4cad6a2ac1fdde81b7a2b8514c3b967838f322c6..3ee771393d65ca6a20fc17b5dd30c8ecc2d6348c 100644 (file)
@@ -58,7 +58,8 @@ namespace System.Web.UI {
                
                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;
@@ -144,12 +145,13 @@ namespace System.Web.UI {
                        }
 
                        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);
index 71fa708e8bcaa771b600d8233c66313e50b51ade..6a9ed3d1966c35d7eec423610303908e2b5525b5 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-08  Marek Habersack  <mhabersack@novell.com>
+
+       * ControlParameterTest.cs: added a test for ControlParameter
+       evaluating a complex property expression.
+
 2008-09-30  Sebastien Pouliot  <sebastien@ximian.com>
 
        * RoleGroupCollectionTest.cs: Add test case this[int].
index b62b5101b0b6668a760b11876e08b850aebaa318..b0d61d68579b88b504d1f3a9c644cd11d31930af 100644 (file)
@@ -31,6 +31,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Collections.Specialized;
 using System.Text;
 using NUnit.Framework;
 using System.Web;
@@ -39,63 +40,77 @@ using System.Web.UI.WebControls;
 
 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]
@@ -163,6 +178,23 @@ namespace MonoTests.System.Web.UI.WebControls
                        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 ()