Actions.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /// Spart License (zlib/png)
  2. ///
  3. ///
  4. /// Copyright (c) 2003 Jonathan de Halleux
  5. ///
  6. /// This software is provided 'as-is', without any express or implied warranty.
  7. /// In no event will the authors be held liable for any damages arising from
  8. /// the use of this software.
  9. ///
  10. /// Permission is granted to anyone to use this software for any purpose,
  11. /// including commercial applications, and to alter it and redistribute it
  12. /// freely, subject to the following restrictions:
  13. ///
  14. /// 1. The origin of this software must not be misrepresented; you must not
  15. /// claim that you wrote the original software. If you use this software in a
  16. /// product, an acknowledgment in the product documentation would be
  17. /// appreciated but is not required.
  18. ///
  19. /// 2. Altered source versions must be plainly marked as such, and must not be
  20. /// misrepresented as being the original software.
  21. ///
  22. /// 3. This notice may not be removed or altered from any source distribution.
  23. ///
  24. /// Author: Jonathan de Halleuxusing System;
  25. using System;
  26. using System.Collections;
  27. using Spart.Actions.Actors;
  28. namespace Spart.Actions
  29. {
  30. /// <summary>
  31. /// Static helper class that creates actors
  32. /// </summary>
  33. public class Actor
  34. {
  35. /// <summary>
  36. /// Create an actor that append the parse result to a <see cref="IList"/>.
  37. /// </summary>
  38. /// <param name="list"></param>
  39. /// <returns></returns>
  40. public static ActionHandler Append(IList list)
  41. {
  42. AppendActor a = new AppendActor(list);
  43. return new ActionHandler( a.DoAction );
  44. }
  45. /// <summary>
  46. /// Create an actor that assign the parse result to an object
  47. /// </summary>
  48. /// <param name="o"></param>
  49. /// <returns></returns>
  50. public static ActionHandler Assign(Object o)
  51. {
  52. AssignActor a = new AssignActor(o);
  53. return new ActionHandler( a.DoAction );
  54. }
  55. /// <summary>
  56. /// Creates an actor that throws an exception
  57. /// </summary>
  58. /// <param name="ex"></param>
  59. /// <returns></returns>
  60. public static ActionHandler Throw(Exception ex)
  61. {
  62. ThrowActor a = new ThrowActor(ex);
  63. return new ActionHandler( a.DoAction );
  64. }
  65. }
  66. }