-//
+//
// System.Web.UI.DataSourceSelectArguments.cs
//
// Author:
{
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 ();
}
}
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 {
}
public string SortExpression {
- get { return this.sortExpression; }
+ get {
+ if (sortExpression == null)
+ return String.Empty;
+ return this.sortExpression;
+ }
set { this.sortExpression = value; }
}