Merge pull request #1304 from slluis/mac-proxy-autoconfig
[mono.git] / mcs / class / System.Data / System.Data / DataRow.cs
index 6b6299f41a82c490d4a0e79d244fbc197633cfd9..2d0df625f37bf7cbec2ba369d04a77211a4b7f20 100644 (file)
@@ -96,6 +96,7 @@ namespace System.Data {
                {
                        _table = table;
                        _rowId = rowId;
+                       rowError = String.Empty;
                }
 
                #endregion // Constructors
@@ -117,11 +118,11 @@ namespace System.Data {
                /// </summary>
                public bool HasErrors {
                        get {
-                               if (RowError != string.Empty)
+                               if (!string.IsNullOrEmpty (RowError))
                                        return true;
 
                                foreach (String columnError in ColumnErrors) {
-                                       if (columnError != null && columnError != string.Empty)
+                                       if (!string.IsNullOrEmpty (columnError))
                                                return true;
                                }
                                return false;
@@ -134,10 +135,7 @@ namespace System.Data {
                public object this [string columnName] {
                        get { return this [columnName, DataRowVersion.Default]; }
                        set {
-                               DataColumn column = _table.Columns [columnName];
-                               if (column == null)
-                                       throw new ArgumentException ("The column '" + columnName +
-                                               "' does not belong to the table : " + _table.TableName);
+                               DataColumn column = GetColumn (columnName);
                                this [column.Ordinal] = value;
                        }
                }
@@ -202,10 +200,7 @@ namespace System.Data {
                /// </summary>
                public object this [string columnName, DataRowVersion version] {
                        get {
-                               DataColumn column = _table.Columns [columnName];
-                               if (column == null)
-                                       throw new ArgumentException ("The column '" + columnName +
-                                               "' does not belong to the table : " + _table.TableName);
+                               DataColumn column = GetColumn (columnName);
                                return this [column.Ordinal, version];
                        }
                }
@@ -514,7 +509,7 @@ namespace System.Data {
                /// </summary>
                public string RowError {
                        get { return rowError; }
-                       set { rowError = value; }
+                       set { rowError = value ?? string.Empty; }
                }
 
                internal int IndexFromVersion (DataRowVersion version)
@@ -1248,7 +1243,7 @@ namespace System.Data {
                /// </summary>
                public bool IsNull (string columnName)
                {
-                       return IsNull (Table.Columns [columnName]);
+                       return IsNull (GetColumn (columnName));
                }
 
                /// <summary>
@@ -1257,6 +1252,17 @@ namespace System.Data {
                /// </summary>
                public bool IsNull (DataColumn column, DataRowVersion version)
                {
+                       if (column == null)
+                               throw new ArgumentNullException ("column");
+
+                       // use the expresion if there is one
+                       if (column.Expression != String.Empty) {
+                               // FIXME: how does this handle 'version'?
+                               // TODO: Can we avoid the Eval each time by using the cached value?
+                               object o = column.CompiledExpression.Eval (this);
+                               return o == null && o == DBNull.Value;
+                       }
+
                        return column.DataContainer.IsNull (IndexFromVersion (version));
                }
 
@@ -1692,5 +1698,15 @@ namespace System.Data {
                        }
                }
 #endif // NET_2_0
+
+               DataColumn GetColumn (string columnName)
+               {
+                       DataColumn column = _table.Columns [columnName];
+
+                       if (column == null)
+                               throw new ArgumentException ("The column '" + columnName + "' does not belong to the table " + _table.TableName);
+
+                       return column;
+               }
        }
 }