JavaScriptConstructor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #region License
  2. // Copyright (c) 2007 James Newton-King
  3. //
  4. // Permission is hereby granted, free of charge, to any person
  5. // obtaining a copy of this software and associated documentation
  6. // files (the "Software"), to deal in the Software without
  7. // restriction, including without limitation the rights to use,
  8. // copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following
  11. // conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be
  14. // included in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. // OTHER DEALINGS IN THE SOFTWARE.
  24. #endregion
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Text;
  28. namespace Newtonsoft.Json
  29. {
  30. /// <summary>
  31. /// Represents a JavaScript constructor.
  32. /// </summary>
  33. sealed class JavaScriptConstructor
  34. {
  35. private string _name;
  36. private JavaScriptParameters _parameters;
  37. public JavaScriptParameters Parameters
  38. {
  39. get { return _parameters; }
  40. }
  41. public string Name
  42. {
  43. get { return _name; }
  44. }
  45. public JavaScriptConstructor(string name, JavaScriptParameters parameters)
  46. {
  47. if (name == null)
  48. throw new ArgumentNullException("name");
  49. if (name.Length == 0)
  50. throw new ArgumentException("Constructor name cannot be empty.", "name");
  51. _name = name;
  52. _parameters = parameters ?? JavaScriptParameters.Empty;
  53. }
  54. public override string ToString()
  55. {
  56. StringBuilder sb = new StringBuilder();
  57. sb.Append("new ");
  58. sb.Append(_name);
  59. sb.Append("(");
  60. if (_parameters != null)
  61. {
  62. for (int i = 0; i < _parameters.Count; i++)
  63. {
  64. sb.Append(_parameters[i]);
  65. }
  66. }
  67. sb.Append(")");
  68. return sb.ToString();
  69. }
  70. }
  71. }