ValidatedControlConverter.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.Collections;
  16. using System.Web;
  17. using System.Web.UI;
  18. namespace System.Web.UI.WebControls
  19. {
  20. public class ValidatedControlConverter : StringConverter
  21. {
  22. public ValidatedControlConverter(): base()
  23. {
  24. }
  25. private object[] GetValues(IContainer container)
  26. {
  27. ArrayList values = new ArrayList();
  28. IEnumerator ie = container.Components.GetEnumerator();
  29. try
  30. {
  31. foreach(IComponent current in container.Components)
  32. {
  33. Control ctrl = (Control)current;
  34. if(ctrl == null || ctrl.ID == null || ctrl.ID.Length == 0)
  35. continue;
  36. ValidationPropertyAttribute attrib = (ValidationPropertyAttribute)((TypeDescriptor.GetAttributes(ctrl))[typeof(ValidationPropertyAttribute)]);
  37. if(attrib == null || attrib.Name == null)
  38. continue;
  39. values.Add(String.Copy(ctrl.ID));
  40. }
  41. }finally
  42. {
  43. if(ie is IDisposable)
  44. ((IDisposable)ie).Dispose();
  45. }
  46. values.Sort();
  47. return values.ToArray();
  48. }
  49. public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
  50. {
  51. if(context != null && context.Container != null)
  52. {
  53. object[] values = GetValues(context.Container);
  54. if(values != null)
  55. {
  56. return new StandardValuesCollection(values);
  57. }
  58. }
  59. return null;
  60. }
  61. public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  62. {
  63. return false;
  64. }
  65. public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  66. {
  67. return true;
  68. }
  69. }
  70. }