DataSourceHelper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Namespace: System.Web.UI.Util
  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.Util
  16. {
  17. internal class DataSourceHelper
  18. {
  19. public static IEnumerable GetResolvedDataSource(object source, string member)
  20. {
  21. if(source != null && source is IListSource)
  22. {
  23. IListSource src = (IListSource)source;
  24. IList list = src.GetList();
  25. if(!src.ContainsListCollection)
  26. {
  27. return list;
  28. }
  29. if(list != null && list is ITypedList)
  30. {
  31. ITypedList tlist = (ITypedList)list;
  32. PropertyDescriptorCollection pdc = tlist.GetItemProperties(new PropertyDescriptor[0]);
  33. if(pdc != null && pdc.Count > 0)
  34. {
  35. PropertyDescriptor pd = null;
  36. if(member != null && member.Length > 0)
  37. {
  38. pd = pdc.Find(member, true);
  39. } else
  40. {
  41. pd = pdc[0];
  42. }
  43. if(pd != null)
  44. {
  45. object rv = pd.GetValue(list[0]);
  46. if(rv != null && rv is IEnumerable)
  47. {
  48. return (IEnumerable)rv;
  49. }
  50. }
  51. throw new HttpException(
  52. HttpRuntime.FormatResourceString("ListSource_Missing_DataMember", member));
  53. }
  54. throw new HttpException(
  55. HttpRuntime.FormatResourceString("ListSource_Without_DataMembers"));
  56. }
  57. }
  58. if(source is IEnumerable)
  59. {
  60. return (IEnumerable)source;
  61. }
  62. return null;
  63. }
  64. }
  65. }