ValidatedControlConverter.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: ValidatedControlConverter
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.ComponentModel;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. public class ValidatedControlConverter : StringConverter
  20. {
  21. public ValidatedControlConverter(): base()
  22. {
  23. }
  24. private object[] GetValues(IContainer container)
  25. {
  26. ArrayList values = new ArrayList();
  27. IEnumerator ie = container.Components.GetEnumerator();
  28. try
  29. {
  30. foreach(IComponent current in container.Components)
  31. {
  32. Control ctrl = (Control)current;
  33. if(ctrl == null || ctrl.ID == null || ctrl.ID.Length == 0)
  34. continue;
  35. ValidationPropertyAttribute attrib = (ValidationPropertyAttribute)((TypeDescriptor.GetAttributes(ctrl))[typeof(ValidationPropertyAttribute)]);
  36. if(attrib == null || attrib.Name == null)
  37. continue;
  38. values.Add(String.Copy(ctrl.ID));
  39. }
  40. }finally
  41. {
  42. if(ie is IDisposable)
  43. ie.Dispose();
  44. }
  45. values.Sort();
  46. return values.ToArray();
  47. }
  48. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  49. {
  50. if(context != null && context.Container != null)
  51. {
  52. object[] values = GetValues(context.Container);
  53. if(values != null)
  54. {
  55. return new StandardValuesCollection(values);
  56. }
  57. }
  58. return null;
  59. }
  60. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  61. {
  62. return false;
  63. }
  64. public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  65. {
  66. return true;
  67. }
  68. }
  69. }