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

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : VariableAdapter.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.Web.UI;
  11. using Itenso.WebUserForms.Controls;
  12. using Itenso.WebUserForms.Data.Variable;
  13. namespace Itenso.WebUserForms.Runtime
  14. {
  15. // ------------------------------------------------------------------------
  16. public sealed class VariableAdapter
  17. {
  18. // ----------------------------------------------------------------------
  19. private VariableAdapter()
  20. {
  21. } // VariableAdapter
  22. // ----------------------------------------------------------------------
  23. public static void ExpandVariables( IVariableProvider variableProvider, UserControl userControl )
  24. {
  25. if ( variableProvider == null )
  26. {
  27. throw new ArgumentNullException( "variableProvider" );
  28. }
  29. if ( userControl == null )
  30. {
  31. throw new ArgumentNullException( "userControl" );
  32. }
  33. IVariableSet variableSet = variableProvider.GetVariables( null );
  34. if ( variableSet == null )
  35. {
  36. return;
  37. }
  38. ExpandVariables( variableSet, userControl );
  39. } // ExpandVariables
  40. // ----------------------------------------------------------------------
  41. public static void ExpandVariables( IVariableSet variableSet, UserControl userControl )
  42. {
  43. if ( variableSet == null )
  44. {
  45. throw new ArgumentNullException( "variableSet" );
  46. }
  47. if ( userControl == null )
  48. {
  49. throw new ArgumentNullException( "userControl" );
  50. }
  51. if ( variableSet.Count == 0 )
  52. {
  53. return; // nothing to do
  54. }
  55. ExpressionFieldCollector expressionFieldCollector = new ExpressionFieldCollector( userControl );
  56. expressionFieldCollector.Collect();
  57. foreach ( IExpressionField expressionField in expressionFieldCollector.ExpressionFields )
  58. {
  59. string fieldExpression = expressionField.FieldExpression;
  60. if ( string.IsNullOrEmpty( fieldExpression ) )
  61. {
  62. continue;
  63. }
  64. string expandedFieldExpression = variableSet.Expand( fieldExpression );
  65. expressionField.FieldValue = expandedFieldExpression;
  66. }
  67. } // ExpandVariables
  68. } // class VariableAdapter
  69. } // namespace Itenso.WebUserForms.Runtime
  70. // -- EOF -------------------------------------------------------------------