-JSON Schema fixes

-Fixed static values being included with fields serialization
-Examples! (work in progress)
This commit is contained in:
James Newton-King
2013-01-23 21:39:54 +13:00
parent 9187d8a6b3
commit 68eacc480b
87 changed files with 3519 additions and 53 deletions
+45 -39
View File
@@ -167,6 +167,51 @@ namespace Newtonsoft.Json.Linq
internal set { _previous = value; }
}
/// <summary>
/// Gets the path of the JSON token.
/// </summary>
public string Path
{
get
{
if (Parent == null)
return string.Empty;
IList<JToken> ancestors = Ancestors().Reverse().ToList();
ancestors.Add(this);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ancestors.Count; i++)
{
JToken current = ancestors[i];
JToken next = (i + 1 < ancestors.Count) ? ancestors[i + 1] : null;
if (next != null)
{
switch (current.Type)
{
case JTokenType.Property:
JProperty property = (JProperty)current;
if (sb.Length > 0)
sb.Append(".");
sb.Append(property.Name);
break;
case JTokenType.Array:
case JTokenType.Constructor:
int index = ((IList<JToken>)current).IndexOf(next);
sb.Append("[" + index + "]");
break;
}
}
}
return sb.ToString();
}
}
internal JToken()
{
}
@@ -1700,44 +1745,5 @@ namespace Newtonsoft.Json.Linq
{
return CloneToken();
}
public string Path
{
get
{
IList<JToken> ancestors = Ancestors().Reverse().ToList();
ancestors.Add(this);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ancestors.Count; i++)
{
JToken current = ancestors[i];
JToken next = (i + 1 < ancestors.Count) ? ancestors[i + 1] : null;
if (next != null)
{
switch (current.Type)
{
case JTokenType.Property:
JProperty property = (JProperty) current;
if (sb.Length > 0)
sb.Append(".");
sb.Append(property.Name);
break;
case JTokenType.Array:
case JTokenType.Constructor:
int index = ((IList<JToken>)current).IndexOf(next);
sb.Append("[" + index + "]");
break;
}
}
}
return sb.ToString();
}
}
}
}