ControlFieldCollector.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:2k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : FieldFinder.cs
  3. // project    : Itenso Web User Forms
  4. // created    : Jani Giannoudis - 2008.10.30
  5. // language   : c#
  6. // environment: .NET 2.0
  7. // copyright  : (c) 2008 by Itenso GmbH, Switzerland
  8. // --------------------------------------------------------------------------
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Web.UI;
  12. namespace Itenso.WebUserForms.Controls
  13. {
  14. // ------------------------------------------------------------------------
  15. public class ControlFieldCollector : UserFormVisitor
  16. {
  17. // ----------------------------------------------------------------------
  18. public ControlFieldCollector( Control startControl, string fieldName )
  19. : base( startControl )
  20. {
  21. if ( string.IsNullOrEmpty( fieldName ) )
  22. {
  23. throw new ArgumentException( "fieldName" );
  24. }
  25. this.fieldName = fieldName;
  26. } // FieldFinder
  27. // ----------------------------------------------------------------------
  28. public string FieldName
  29. {
  30. get { return this.fieldName; }
  31. } // FieldName
  32. // ----------------------------------------------------------------------
  33. public List<Control> Controls
  34. {
  35. get { return this.controls; }
  36. } // Controls
  37. // ----------------------------------------------------------------------
  38. public void Collect()
  39. {
  40. this.controls.Clear();
  41. Start();
  42. } // Collect
  43. // ----------------------------------------------------------------------
  44. public static List<Control> Collect( Control startControl, string fieldName )
  45. {
  46. ControlFieldCollector controlFieldCollector = new ControlFieldCollector( startControl, fieldName );
  47. controlFieldCollector.Collect();
  48. return controlFieldCollector.Controls;
  49. } // Collect
  50. // ----------------------------------------------------------------------
  51. protected override void VisitFormField( Control control,
  52. IUserFormField formField, IUserFormHeader formHeader )
  53. {
  54. if ( this.fieldName.Equals( formField.FieldName ) )
  55. {
  56. this.controls.Add( control );
  57. }
  58. } // VisitFormField
  59. // ----------------------------------------------------------------------
  60. // members
  61. private readonly List<Control> controls = new List<Control>();
  62. private readonly string fieldName;
  63. } // class FieldFinder
  64. } // namespace Itenso.WebUserForms.Controls
  65. // -- EOF -------------------------------------------------------------------