Author: igorz
Date: 2007-01-02 07:03:01 -0500 (Tue, 02 Jan 2007)
New Revision: 70347
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs
Log:
2007-01-02 Igor Zelmanovich <[EMAIL PROTECTED]>
* DetailsView.cs: fixed CreateAutoGeneratedRows.
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2007-01-02 11:49:55 UTC (rev 70346)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2007-01-02 12:03:01 UTC (rev 70347)
@@ -1,3 +1,7 @@
+2007-01-02 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * DetailsView.cs: fixed CreateAutoGeneratedRows.
+
2007-01-01 Igor Zelmanovich <[EMAIL PROTECTED]>
* AutoGeneratedField.cs: is editable in Insest mode.
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs
2007-01-02 11:49:55 UTC (rev 70346)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs
2007-01-02 12:03:01 UTC (rev 70347)
@@ -981,6 +981,9 @@
protected virtual ICollection CreateAutoGeneratedRows (object
dataItem)
{
+ if (dataItem == null)
+ return null;
+
ArrayList list = new ArrayList ();
autoFieldProperties = CreateAutoFieldProperties
(dataItem);
foreach (AutoGeneratedFieldProperties props in
autoFieldProperties)
@@ -995,28 +998,40 @@
AutoGeneratedFieldProperties[] CreateAutoFieldProperties
(object dataItem)
{
- PropertyDescriptorCollection props =
TypeDescriptor.GetProperties (dataItem);
-
- ArrayList retVal = new ArrayList();
- if (props != null && props.Count > 0)
+ if (IsBindableType (dataItem.GetType ()))
{
+ AutoGeneratedFieldProperties field = new
AutoGeneratedFieldProperties ();
+ ((IStateManager) field).TrackViewState ();
+ field.Name = "Item";
+ field.DataField = BoundField.ThisExpression;
+ field.Type = dataItem.GetType ();
+ return new AutoGeneratedFieldProperties [] {
field };
+ }
+
+ PropertyDescriptorCollection props =
TypeDescriptor.GetProperties (dataItem, false);
+
+ if (props != null && props.Count > 0) {
+ ArrayList retVal = new ArrayList ();
foreach (PropertyDescriptor current in props) {
if (IsBindableType
(current.PropertyType)) {
AutoGeneratedFieldProperties
field = new AutoGeneratedFieldProperties ();
-
((IStateManager)field).TrackViewState();
+ ((IStateManager)
field).TrackViewState ();
field.Name = current.Name;
field.DataField = current.Name;
- field.IsReadOnly =
current.IsReadOnly;
+ for (int i = 0; i <
DataKeyNames.Length; i++) {
+ if (string.Compare
(DataKeyNames [i], current.Name, StringComparison.InvariantCultureIgnoreCase)
== 0) {
+
field.IsReadOnly = true;
+ break;
+ }
+ }
field.Type =
current.PropertyType;
retVal.Add (field);
}
}
+ if (retVal.Count > 0)
+ return (AutoGeneratedFieldProperties
[]) retVal.ToArray (typeof (AutoGeneratedFieldProperties));
}
-
- if (retVal.Count > 0)
- return (AutoGeneratedFieldProperties[])
retVal.ToArray (typeof(AutoGeneratedFieldProperties));
- else
- return new AutoGeneratedFieldProperties [0];
+ throw new HttpException (String.Format ("DetailsView
with id '{0}' did not have any properties or attributes from which to generate
fields. Ensure that your data source has content.", ID));
}
protected virtual DetailsViewRow CreateRow (int rowIndex,
DataControlRowType rowType, DataControlRowState rowState)
Modified: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
2007-01-02 11:49:55 UTC (rev 70346)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
2007-01-02 12:03:01 UTC (rev 70347)
@@ -1,3 +1,7 @@
+2007-01-02 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * DetailsViewTest.cs: new tests, removed NotWorking attribute.
+
2007-01-01 Igor Zelmanovich <[EMAIL PROTECTED]>
* DetailsViewTest.cs: fixed tests, removed NotWorking attribute.
Modified:
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs
===================================================================
---
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs
2007-01-02 11:49:55 UTC (rev 70346)
+++
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs
2007-01-02 12:03:01 UTC (rev 70347)
@@ -81,6 +81,41 @@
}
}
+ public class TestObject
+ {
+ public int TestInt {
+ get { return 10; }
+ set { }
+ }
+
+ public int TestIntReadOnly {
+ get { return 10; }
+ }
+
+ public string TestString {
+ get { return "val"; }
+ set { }
+ }
+
+ public string TestStringReadOnly {
+ get { return "val"; }
+ }
+
+ public string this [int i] {
+ get { return "aaa"; }
+ set { }
+ }
+
+ }
+
+ public class TestObject2
+ {
+ public Object Property {
+ get { return null; }
+ set { }
+ }
+ }
+
public class PokerDetailsView: DetailsView
{
public bool ensureDataBound=false;
@@ -952,7 +987,6 @@
}
[Test]
- [Category ("NotWorking")]
public void DetailsView_CreateFieldSet_dont_useDataSource ()
{
DataTable ds = TableObject.CreateDataTable ();
@@ -985,6 +1019,43 @@
}
[Test]
+ public void DetailsView_CreateAutoGeneratedRows2 ()
+ {
+ PokerDetailsView dv = new PokerDetailsView ();
+ ICollection col = dv.DoCreateAutoGeneratedRows (new
TestObject ());
+
+ Assert.AreEqual (typeof (ArrayList), col.GetType (),
"CreateAutoGeneratedRowsType");
+ Assert.AreEqual (4, col.Count,
"CreateAutoGeneratedRowsCount");
+ Assert.AreEqual (typeof (AutoGeneratedField),
((ArrayList) col) [0].GetType (), "AutoGeneratedRowType");
+
+ Assert.IsFalse (((AutoGeneratedField) ((ArrayList) col)
[0]).ReadOnly, "AutoGeneratedRowReadOnly1");
+ Assert.IsFalse (((AutoGeneratedField) ((ArrayList) col)
[1]).ReadOnly, "AutoGeneratedRowReadOnly2");
+ Assert.IsFalse (((AutoGeneratedField) ((ArrayList) col)
[2]).ReadOnly, "AutoGeneratedRowReadOnly2");
+ Assert.IsFalse (((AutoGeneratedField) ((ArrayList) col)
[3]).ReadOnly, "AutoGeneratedRowReadOnly3");
+
+ col = dv.DoCreateAutoGeneratedRows ("aaa");
+ Assert.AreEqual (1, col.Count,
"CreateAutoGeneratedRowsCount - IsBindableType");
+
+ col = dv.DoCreateAutoGeneratedRows (null);
+ Assert.AreEqual (null, col, "null");
+ }
+
+ [Test]
+ [ExpectedException (typeof (HttpException))]
+ public void DetailsView_CreateAutoGeneratedRows_Ex ()
+ {
+ PokerDetailsView dv = new PokerDetailsView ();
+ ICollection col = dv.DoCreateAutoGeneratedRows (new
Object());
+ }
+
+ [Test]
+ [ExpectedException (typeof (HttpException))]
+ public void DetailsView_CreateAutoGeneratedRows_Ex2 () {
+ PokerDetailsView dv = new PokerDetailsView ();
+ ICollection col = dv.DoCreateAutoGeneratedRows (new
Object ());
+ }
+
+ [Test]
public void DetailsView_GetCallBackResult ()
{
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches