From c7d99fbd3fd94f8e76b3f2009e95051eb582189b Mon Sep 17 00:00:00 2001 From: JamesNK Date: Sat, 23 Aug 2008 04:56:24 +0000 Subject: [PATCH] -Added IJEnumerable. Changed JEnumerable and JToken to both implement IJEnumerable. -Included missing JsonConverters from Newtonsoft.Json.Silverlight project. --- Src/Newtonsoft.Json/Linq/IJEnumerable.cs | 20 +++++++++++++++++++ Src/Newtonsoft.Json/Linq/JEnumerable.cs | 8 ++++---- Src/Newtonsoft.Json/Linq/JToken.cs | 7 ++++++- .../Newtonsoft.Json.Silverlight.csproj | 9 ++++++--- Src/Newtonsoft.Json/Newtonsoft.Json.csproj | 3 ++- 5 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 Src/Newtonsoft.Json/Linq/IJEnumerable.cs diff --git a/Src/Newtonsoft.Json/Linq/IJEnumerable.cs b/Src/Newtonsoft.Json/Linq/IJEnumerable.cs new file mode 100644 index 00000000..a758fcb1 --- /dev/null +++ b/Src/Newtonsoft.Json/Linq/IJEnumerable.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Newtonsoft.Json.Linq +{ + /// + /// Represents a collection of objects. + /// + /// The type of token + public interface IJEnumerable : IEnumerable where T : JToken + { + /// + /// Gets the with the specified key. + /// + /// + IJEnumerable this[object key] { get; } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Linq/JEnumerable.cs b/Src/Newtonsoft.Json/Linq/JEnumerable.cs index 3762ef93..ae1f8d25 100644 --- a/Src/Newtonsoft.Json/Linq/JEnumerable.cs +++ b/Src/Newtonsoft.Json/Linq/JEnumerable.cs @@ -11,7 +11,7 @@ namespace Newtonsoft.Json.Linq /// Represents a collection of objects. /// /// The type of token - public struct JEnumerable : IEnumerable where T : JToken + public struct JEnumerable : IJEnumerable where T : JToken { /// /// An empty collection of objects. @@ -54,12 +54,12 @@ namespace Newtonsoft.Json.Linq } /// - /// Gets the with the specified key. + /// Gets the with the specified key. /// /// - public IEnumerable this[object key] + public IJEnumerable this[object key] { - get { return Extensions.Values(_enumerable, key); } + get { return new JEnumerable(Extensions.Values(_enumerable, key)); } } } } diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 91b1ee1c..085cc193 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -38,7 +38,7 @@ namespace Newtonsoft.Json.Linq /// /// Represents an abstract JSON token. /// - public abstract class JToken : IEnumerable + public abstract class JToken : IJEnumerable { private JContainer _parent; internal JToken _next; @@ -723,5 +723,10 @@ namespace Newtonsoft.Json.Linq } internal abstract int GetDeepHashCode(); + + IJEnumerable IJEnumerable.this[object key] + { + get { return Children()[key]; } + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj index cc214771..7be195c5 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj @@ -211,6 +211,11 @@ Utilities\ValidationUtils.cs + + + + + @@ -230,6 +235,7 @@ + @@ -263,9 +269,6 @@ - - -