2 // System.Web.UI.ListSourceHelper
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.Collections.Generic;
38 namespace System.Web.UI {
39 public static class ListSourceHelper {
41 public static bool ContainsListCollection (IDataSource dataSource)
43 return dataSource.GetViewNames ().Count > 0;
46 public static IList GetList (IDataSource dataSource)
48 if (dataSource.GetViewNames ().Count == 0)
51 ListSourceList list = new ListSourceList ();
52 list.Add (dataSource);
56 sealed class ListSourceList : List<IDataSource>, ITypedList
58 #region ITypedList Members
60 PropertyDescriptorCollection ITypedList.GetItemProperties (PropertyDescriptor [] listAccessors) {
61 ICollection viewNames = this [0].GetViewNames ();
62 PropertyDescriptor [] a = new PropertyDescriptor [viewNames.Count];
64 foreach (string viewName in viewNames) {
65 a[i++] = new ListSourcePropertyDescriptor (viewName, null);
67 return new PropertyDescriptorCollection (a);
70 string ITypedList.GetListName (PropertyDescriptor [] listAccessors) {
77 sealed class ListSourcePropertyDescriptor : PropertyDescriptor
79 public ListSourcePropertyDescriptor (MemberDescriptor descr)
83 public ListSourcePropertyDescriptor (string name, Attribute [] attrs)
84 : base (name, attrs) {
87 public ListSourcePropertyDescriptor (MemberDescriptor descr, Attribute [] attrs)
88 : base (descr, attrs) {
91 public override bool CanResetValue (object component) {
92 throw new NotImplementedException ();
95 public override Type ComponentType {
96 get { throw new NotImplementedException (); }
99 public override object GetValue (object component) {
100 IDataSource dataSource = component as IDataSource;
101 if (dataSource == null)
104 DataSourceView view = dataSource.GetView (Name);
105 return view.ExecuteSelect (DataSourceSelectArguments.Empty);
108 public override bool IsReadOnly {
112 public override Type PropertyType {
113 get { return typeof(IEnumerable); }
116 public override void ResetValue (object component) {
117 throw new NotImplementedException ();
120 public override void SetValue (object component, object value) {
121 throw new NotImplementedException ();
124 public override bool ShouldSerializeValue (object component) {
125 throw new NotImplementedException ();