Implemented a few missing properties
[mono.git] / mcs / class / System.Web / System.Web.UI / DataSourceSelectArguments.cs
index d00dae48ed64fbc5f080629d4482ab9a0c51c9bf..bca38f16d8b72ac00e279d8dab02e326ca1e3aba 100644 (file)
@@ -1,4 +1,4 @@
-//
+//
 // System.Web.UI.DataSourceSelectArguments.cs
 //
 // Author:
@@ -35,17 +35,17 @@ namespace System.Web.UI
 {
        public sealed class DataSourceSelectArguments
        {
-               string sortExpression = string.Empty;
-               int startingRowIndex = 0;
-               int maxRows = 0;
-               bool getTotalRowCount = false;
+               string sortExpression;
+               int startingRowIndex;
+               int maxRows;
+               bool getTotalRowCount;
                int totalRowCount = -1;
                DataSourceCapabilities dsc = DataSourceCapabilities.None;
 
-               static DataSourceSelectArguments empty = new DataSourceSelectArguments();
+               // MSDN: Gets a DataSourceSelectArguments object with the sort expression set to Empty. 
                public static DataSourceSelectArguments Empty {
                        get {
-                               return empty;
+                               return new DataSourceSelectArguments ();
                        }
                }
 
@@ -76,33 +76,66 @@ namespace System.Web.UI
                        this.dsc = this.dsc | srcCapabilities;
                }
 
+               // 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;
 
-                       DataSourceSelectArguments args = (DataSourceSelectArguments)obj;
-                       return (this.sortExpression == args.sortExpression &&
-                               this.startingRowIndex == args.startingRowIndex &&
-                               this.maxRows == args.maxRows);
+                       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);
+               }
+
+               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;
-                       }
+                       set { this.maxRows = value; }
                }
 
                public bool RetrieveTotalRowCount  {
@@ -111,24 +144,22 @@ namespace System.Web.UI
                }
 
                public string SortExpression {
-                       get { return this.sortExpression; }
-                       set {
-                               this.sortExpression = value;
+                       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;
-                       }
+                       set { this.startingRowIndex = value; }
                }
 
                public int TotalRowCount {
                        get { return this.totalRowCount; }
-                       set {
-                               this.totalRowCount = value;
-                       }
+                       set { this.totalRowCount = value; }
                }
        }
 }