Implemented a few missing properties
[mono.git] / mcs / class / System.Web / System.Web.UI / DataSourceSelectArguments.cs
index ee26e6d7b305e529749857acda67287a36f14fe9..bca38f16d8b72ac00e279d8dab02e326ca1e3aba 100644 (file)
@@ -1,4 +1,4 @@
-//
+//
 // System.Web.UI.DataSourceSelectArguments.cs
 //
 // Author:
@@ -35,32 +35,33 @@ namespace System.Web.UI
 {
        public sealed class DataSourceSelectArguments
        {
-               string sortExpression = string.Empty;
-               int startingRowIndex = 0;
-               int maxRows = 0;
-               bool isEmpty;
-               bool getTotalRowCount = false;
+               string sortExpression;
+               int startingRowIndex;
+               int maxRows;
+               bool getTotalRowCount;
                int totalRowCount = -1;
                DataSourceCapabilities dsc = DataSourceCapabilities.None;
 
-               public static readonly DataSourceSelectArguments Empty = new DataSourceSelectArguments ();
+               // MSDN: Gets a DataSourceSelectArguments object with the sort expression set to Empty. 
+               public static DataSourceSelectArguments Empty {
+                       get {
+                               return new DataSourceSelectArguments ();
+                       }
+               }
 
                public DataSourceSelectArguments ()
                {
-                       this.isEmpty = true;
                }
 
                public DataSourceSelectArguments (string sortExpression)
                {
                        this.sortExpression = sortExpression;
-                       this.isEmpty = false;
                }
 
                public DataSourceSelectArguments (int startingRowIndex, int maxRows)
                {
                        this.startingRowIndex = startingRowIndex;
                        this.maxRows = maxRows;
-                       this.isEmpty = false;
                }
 
                public DataSourceSelectArguments (string sortExpression, int startingRowIndex, int maxRows)
@@ -68,7 +69,6 @@ namespace System.Web.UI
                        this.sortExpression = sortExpression; 
                        this.startingRowIndex = startingRowIndex;
                        this.maxRows = maxRows;
-                       this.isEmpty = false;
                }
 
                public void AddSupportedCapabilities (DataSourceCapabilities srcCapabilities)
@@ -76,35 +76,66 @@ namespace System.Web.UI
                        this.dsc = this.dsc | srcCapabilities;
                }
 
-               [MonoTODO]
+               // MSDN: The DataSourceSelectArguments class overrides the Object.Equals method to test 
+               // equality using the various properties of the objects. If the MaximumRows, 
+               // RetrieveTotalRowCount, SortExpression, StartRowIndex, and TotalRowCount properties 
+               // are all equal in value, the Equals(Object) method returns true.
                public override bool Equals (object obj)
                {
-                       if (!(obj is DataSourceSelectArguments))
+                       DataSourceSelectArguments args = obj as DataSourceSelectArguments;
+                       if (args == null)
                                return false;
-                       return false;
+
+                       return (this.SortExpression == args.SortExpression &&
+                               this.StartRowIndex == args.StartRowIndex &&
+                               this.MaximumRows == args.MaximumRows &&
+                               this.RetrieveTotalRowCount == args.RetrieveTotalRowCount &&
+                               this.TotalRowCount == args.TotalRowCount);
                }
 
-               [MonoTODO]
                public override int GetHashCode ()
                {
-                       return sortExpression.GetHashCode ();
+                       int hash = SortExpression != null ? SortExpression.GetHashCode() : 0;
+                       return hash ^ StartRowIndex ^ MaximumRows ^ RetrieveTotalRowCount.GetHashCode() ^ TotalRowCount;
                }
 
+               // The RaiseUnsupportedCapabilitiesError method is used by data-bound controls 
+               // to compare additional requested capabilities represented by the properties 
+               // of the DataSourceSelectArguments class, such as the ability to sort or page 
+               // through a result set, with the capabilities supported by the data source view. 
+               // The view calls its own RaiseUnsupportedCapabilityError method for each possible 
+               // capability defined in the DataSourceCapabilities enumeration. 
                public void RaiseUnsupportedCapabilitiesError (DataSourceView view)
                {
-                       view.RaiseUnsupportedCapabilityError (this.dsc);
+                       DataSourceCapabilities requestedCaps = RequestedCapabilities;
+                       DataSourceCapabilities notSupportedCaps = (requestedCaps ^ dsc) & requestedCaps;
+                       if (notSupportedCaps == DataSourceCapabilities.None)
+                               return;
+
+                       if ((notSupportedCaps & DataSourceCapabilities.RetrieveTotalRowCount) > 0)
+                               notSupportedCaps = DataSourceCapabilities.RetrieveTotalRowCount;
+                       else if ((notSupportedCaps & DataSourceCapabilities.Page) > 0)
+                               notSupportedCaps = DataSourceCapabilities.Page;
+
+                       view.RaiseUnsupportedCapabilityError (notSupportedCaps);
                }
 
-               public bool IsEmpty {
-                       get { return this.isEmpty; }
+               DataSourceCapabilities RequestedCapabilities {
+                       get {
+                               DataSourceCapabilities caps = DataSourceCapabilities.None;
+                               if (!String.IsNullOrEmpty (SortExpression))
+                                       caps |= DataSourceCapabilities.Sort;
+                               if (RetrieveTotalRowCount)
+                                       caps |= DataSourceCapabilities.RetrieveTotalRowCount;
+                               if (StartRowIndex > 0 || MaximumRows > 0)
+                                       caps |= DataSourceCapabilities.Page;
+                               return caps;
+                       }
                }
 
                public int MaximumRows {
                        get { return this.maxRows; }
-                       set {
-                               this.maxRows = value;
-                               this.isEmpty = false;
-                       }
+                       set { this.maxRows = value; }
                }
 
                public bool RetrieveTotalRowCount  {
@@ -113,27 +144,22 @@ namespace System.Web.UI
                }
 
                public string SortExpression {
-                       get { return this.sortExpression; }
-                       set {
-                               this.sortExpression = value;
-                               this.isEmpty = false;
+                       get {
+                               if (sortExpression == null)
+                                       return String.Empty;
+                               return this.sortExpression;
                        }
+                       set { this.sortExpression = value; }
                }
 
                public int StartRowIndex {
                        get { return this.startingRowIndex; }
-                       set {
-                               this.startingRowIndex = value;
-                               this.isEmpty = false;
-                       }
+                       set { this.startingRowIndex = value; }
                }
 
                public int TotalRowCount {
                        get { return this.totalRowCount; }
-                       set {
-                               this.totalRowCount = value;
-                               this.isEmpty = false;
-                       }
+                       set { this.totalRowCount = value; }
                }
        }
 }