You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.6 KiB

  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 Newtonsoft.Json.Utilities;
  26. namespace Newtonsoft.Json.Serialization
  27. {
  28. /// <summary>
  29. /// A camel case naming strategy.
  30. /// </summary>
  31. internal class CamelCaseNamingStrategy : NamingStrategy
  32. {
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="CamelCaseNamingStrategy"/> class.
  35. /// </summary>
  36. /// <param name="processDictionaryKeys">
  37. /// A flag indicating whether dictionary keys should be processed.
  38. /// </param>
  39. /// <param name="overrideSpecifiedNames">
  40. /// A flag indicating whether explicitly specified property names should be processed,
  41. /// e.g. a property name customized with a <see cref="JsonPropertyAttribute"/>.
  42. /// </param>
  43. public CamelCaseNamingStrategy(bool processDictionaryKeys, bool overrideSpecifiedNames)
  44. {
  45. ProcessDictionaryKeys = processDictionaryKeys;
  46. OverrideSpecifiedNames = overrideSpecifiedNames;
  47. }
  48. /// <summary>
  49. /// Initializes a new instance of the <see cref="CamelCaseNamingStrategy"/> class.
  50. /// </summary>
  51. /// <param name="processDictionaryKeys">
  52. /// A flag indicating whether dictionary keys should be processed.
  53. /// </param>
  54. /// <param name="overrideSpecifiedNames">
  55. /// A flag indicating whether explicitly specified property names should be processed,
  56. /// e.g. a property name customized with a <see cref="JsonPropertyAttribute"/>.
  57. /// </param>
  58. /// <param name="processExtensionDataNames">
  59. /// A flag indicating whether extension data names should be processed.
  60. /// </param>
  61. public CamelCaseNamingStrategy(bool processDictionaryKeys, bool overrideSpecifiedNames, bool processExtensionDataNames)
  62. : this(processDictionaryKeys, overrideSpecifiedNames)
  63. {
  64. ProcessExtensionDataNames = processExtensionDataNames;
  65. }
  66. /// <summary>
  67. /// Initializes a new instance of the <see cref="CamelCaseNamingStrategy"/> class.
  68. /// </summary>
  69. public CamelCaseNamingStrategy()
  70. {
  71. }
  72. /// <summary>
  73. /// Resolves the specified property name.
  74. /// </summary>
  75. /// <param name="name">The property name to resolve.</param>
  76. /// <returns>The resolved property name.</returns>
  77. protected override string ResolvePropertyName(string name)
  78. {
  79. return StringUtils.ToCamelCase(name);
  80. }
  81. }
  82. }