-JSON Schema fixes
-Fixed static values being included with fields serialization -Examples! (work in progress)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user