JavaScriptConstructor.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #region License
  2. // Copyright 2006 James Newton-King
  3. // http://www.newtonsoft.com
  4. //
  5. // This work is licensed under the Creative Commons Attribution 2.5 License
  6. // http://creativecommons.org/licenses/by/2.5/
  7. //
  8. // You are free:
  9. // * to copy, distribute, display, and perform the work
  10. // * to make derivative works
  11. // * to make commercial use of the work
  12. //
  13. // Under the following conditions:
  14. // * For any reuse or distribution, you must make clear to others the license terms of this work.
  15. // * Any of these conditions can be waived if you get permission from the copyright holder.
  16. #endregion
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Text;
  20. namespace Newtonsoft.Json
  21. {
  22. /// <summary>
  23. /// Represents a JavaScript constructor.
  24. /// </summary>
  25. sealed class JavaScriptConstructor
  26. {
  27. private string _name;
  28. private JavaScriptParameters _parameters;
  29. public JavaScriptParameters Parameters
  30. {
  31. get { return _parameters; }
  32. }
  33. public string Name
  34. {
  35. get { return _name; }
  36. }
  37. public JavaScriptConstructor(string name, JavaScriptParameters parameters)
  38. {
  39. if (name == null)
  40. throw new ArgumentNullException("name");
  41. if (name.Length == 0)
  42. throw new ArgumentException("Constructor name cannot be empty.", "name");
  43. _name = name;
  44. _parameters = parameters ?? JavaScriptParameters.Empty;
  45. }
  46. public override string ToString()
  47. {
  48. StringBuilder sb = new StringBuilder();
  49. sb.Append("new ");
  50. sb.Append(_name);
  51. sb.Append("(");
  52. if (_parameters != null)
  53. {
  54. for (int i = 0; i < _parameters.Count; i++)
  55. {
  56. sb.Append(_parameters[i]);
  57. }
  58. }
  59. sb.Append(")");
  60. return sb.ToString();
  61. }
  62. }
  63. }