2
0

DataSourceHelper.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Namespace: System.Web.UI.Utils
  3. * Class: DataSourceHelper
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Status: 10%
  9. *
  10. * (C) Gaurav Vaish (2001)
  11. */
  12. using System;
  13. using System.Collections;
  14. using System.ComponentModel;
  15. namespace System.Web.Utils
  16. {
  17. internal class DataSourceHelper
  18. {
  19. public static IEnumerable GetResolvedDataSource(object source, string member)
  20. {
  21. if(source==null)
  22. return null;
  23. if(source is IListSource)
  24. {
  25. IListSource ils = (IListSource)source;
  26. IList il = ils.GetList();
  27. if(ils.ContainsListCollection)
  28. {
  29. return il;
  30. }
  31. if(il is ITypedList)
  32. {
  33. ITypedList itl = (ITypedList)il;
  34. PropertyDescriptorCollection pdc = itl.GetItemProperties(new PropertyDescriptor[0]);
  35. PropertyDescriptor pd = null;
  36. if(pdc != null)
  37. {
  38. if(pdc.Count > 0)
  39. {
  40. if(member != null)
  41. {
  42. if(member.Length > 0)
  43. {
  44. pd = pdc.Find(member, true);
  45. } else
  46. {
  47. pd = pdc[0];
  48. }
  49. }
  50. }
  51. }
  52. if(pd!=null)
  53. {
  54. object o = pd.GetValue(il[0]);
  55. if(o!=null)
  56. {
  57. if(o is IEnumerable)
  58. return (IEnumerable)o;
  59. }
  60. throw new HttpException("ListSource Empty"); // no data in ListSource object
  61. }
  62. }
  63. } else if(source is IEnumerable)
  64. {
  65. return (IEnumerable)source;
  66. }
  67. return null;
  68. }
  69. }
  70. }