PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/WCFWebApi/src/Microsoft.Json/System/Json/JsonValueLinqExtensions.cs

#
C# | 36 lines | 17 code | 3 blank | 16 comment | 0 complexity | a2a8fda9ff3d0c3985f7b03e161368ad MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. // <copyright file="JsonValueLinqExtensions.cs" company="Microsoft Corporation">
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // </copyright>
  4. namespace System.Json
  5. {
  6. using System.Collections.Generic;
  7. /// <summary>
  8. /// This class extends the funcionality of the <see cref="JsonValue"/> type for better Linq support .
  9. /// </summary>
  10. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "Linq is a technical name.")]
  11. public static class JsonValueLinqExtensions
  12. {
  13. /// <summary>
  14. /// Extension method for creating a <see cref="JsonValue"/> from an <see cref="IEnumerable{T}"/> collection of <see cref="JsonValue"/> types.
  15. /// </summary>
  16. /// <param name="items">The enumerable instance.</param>
  17. /// <returns>A <see cref="JsonArray"/> created from the specified items.</returns>
  18. public static JsonArray ToJsonArray(this IEnumerable<JsonValue> items)
  19. {
  20. return new JsonArray(items);
  21. }
  22. /// <summary>
  23. /// Extension method for creating a <see cref="JsonValue"/> from an <see cref="IEnumerable{T}"/> collection of <see cref="KeyValuePair{K,V}"/> of <see cref="String"/> and <see cref="JsonValue"/> types.
  24. /// </summary>
  25. /// <param name="items">The enumerable instance.</param>
  26. /// <returns>A <see cref="JsonValue"/> created from the specified items.</returns>
  27. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "JsonValue implements the nested type in param.")]
  28. public static JsonObject ToJsonObject(this IEnumerable<KeyValuePair<string, JsonValue>> items)
  29. {
  30. return new JsonObject(items);
  31. }
  32. }
  33. }