本文整理汇总了C#中RavenJToken类的典型用法代码示例。如果您正苦于以下问题:C# RavenJToken类的具体用法?C# RavenJToken怎么用?C# RavenJToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RavenJToken类属于命名空间,在下文中一共展示了RavenJToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddParent
private void AddParent(RavenJToken token)
{
if (_token == null)
{
_token = token;
_tokenStack.Push(_token);
return;
}
switch (CurrentToken.Type)
{
case JTokenType.Object:
if (string.IsNullOrEmpty(_tempPropName))
throw new JsonWriterException("Unexpected object token");
((RavenJObject)CurrentToken)[_tempPropName] = token;
_tempPropName = null;
break;
case JTokenType.Array:
if (!string.IsNullOrEmpty(_tempPropName))
throw new JsonWriterException("Unexpected property token");
((RavenJArray)CurrentToken).Add(token);
break;
default:
throw new JsonWriterException("Unexpected token: " + CurrentToken.Type);
}
_tokenStack.Push(token);
}
示例2: StripQuotesIfNeeded
private static string StripQuotesIfNeeded(RavenJToken value)
{
var str = value.ToString(Formatting.None);
if (str.StartsWith("\"") && str.EndsWith("\""))
return str.Substring(1, str.Length - 2);
return str;
}
示例3: ExecuteInternal
private void ExecuteInternal(RavenJToken token)
{
if (token == null)
return; // nothing to do
switch (token.Type)
{
case JTokenType.Array:
foreach (var item in (RavenJArray)token)
{
ExecuteInternal(item);
}
break;
case JTokenType.String:
var value = token.Value<string>();
if (LoadedIds.Add(value) == false)
return;
var includedDoc = Database.Get(value, TransactionInformation);
if (includedDoc != null)
Add(includedDoc.Etag,includedDoc.ToJson());
break;
default:
// here we ignore everything else
// if it ain't a string or array, it is invalid
// as an id
break;
}
}
示例4: WriteValue
private static void WriteValue(RavenJToken token, StringWriter sw, int margin, int indent)
{
switch (token.Type)
{
case JTokenType.Array:
WriteJsonArray((RavenJArray)token, sw, margin, indent);
break;
case JTokenType.Object:
WriteJsonObject((RavenJObject)token, sw, margin, indent);
break;
case JTokenType.Null:
sw.Write("null");
break;
case JTokenType.String:
sw.Write('"');
sw.Write(token.ToString()
.NormalizeWhitespace()
.ShortViewOfString(margin - 2)
);
sw.Write('"');
break;
default:
sw.Write(token.ToString().ShortViewOfString(margin));
break;
}
}
示例5: MatchFilters
public virtual bool MatchFilters(RavenJToken item)
{
foreach (var filter in Filters)
{
bool anyRecords = false;
bool matchedFilter = false;
foreach (var tuple in item.SelectTokenWithRavenSyntaxReturningFlatStructure(filter.Path))
{
if (tuple == null || tuple.Item1 == null)
continue;
anyRecords = true;
var val = tuple.Item1.Type == JTokenType.String
? tuple.Item1.Value<string>()
: tuple.Item1.ToString(Formatting.None);
matchedFilter |= filter.Values.Any(value => String.Equals(val, value, StringComparison.OrdinalIgnoreCase)) ==
filter.ShouldMatch;
}
if (filter.ShouldMatch == false && anyRecords == false) // RDBQA-7
return true;
if (matchedFilter == false)
return false;
}
return true;
}
示例6: WriteValue
private static void WriteValue(RavenJToken token, CountingWriter sw, int width, int numberOfLines)
{
switch (token.Type)
{
case JTokenType.Array:
WriteJsonArray((RavenJArray)token, sw, width, numberOfLines);
break;
case JTokenType.Object:
WriteJsonObject((RavenJObject)token, sw, width, numberOfLines);
break;
case JTokenType.Null:
sw.Write("null");
break;
case JTokenType.String:
sw.Write("\"");
sw.Write(token.ToString()
.NormalizeWhitespace()
.TrimmedViewOfString(width - sw.CharactersOnCurrentLine -1)
);
sw.Write("\"");
break;
default:
sw.Write(token.ToString().TrimmedViewOfString(width - sw.CharactersOnCurrentLine - 1));
break;
}
}
示例7: Visit
private static void Visit(RavenJToken token)
{
switch (token.Type)
{
case JTokenType.Object:
foreach (var item in (RavenJObject)token)
Visit(item.Value);
break;
case JTokenType.Array:
foreach (var items in (RavenJArray)token)
Visit(items);
break;
case JTokenType.Constructor:
case JTokenType.Property:
case JTokenType.Comment:
case JTokenType.None:
case JTokenType.Integer:
case JTokenType.Float:
case JTokenType.String:
case JTokenType.Boolean:
case JTokenType.Null:
case JTokenType.Undefined:
case JTokenType.Date:
case JTokenType.Raw:
case JTokenType.Bytes:
break;
default:
throw new ArgumentOutOfRangeException(token.Type.ToString());
}
}
示例8: GetJsonTokenType
private static JsonToken GetJsonTokenType(RavenJToken token)
{
switch (token.Type)
{
case JTokenType.Integer:
return JsonToken.Integer;
case JTokenType.Float:
return JsonToken.Float;
case JTokenType.String:
return JsonToken.String;
case JTokenType.Boolean:
return JsonToken.Boolean;
case JTokenType.Null:
return JsonToken.Null;
case JTokenType.Undefined:
return JsonToken.Undefined;
case JTokenType.Date:
return JsonToken.Date;
case JTokenType.Raw:
return JsonToken.Raw;
case JTokenType.Bytes:
return JsonToken.Bytes;
default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", token.Type, "Unexpected JTokenType.");
}
}
示例9: ReadRavenJToken
private static IEnumerable<ReadState> ReadRavenJToken(RavenJToken token)
{
if (token is RavenJValue)
{
yield return new ReadState(GetJsonTokenType(token), ((RavenJValue)token).Value);
}
else if (token is RavenJArray)
{
yield return new ReadState(JsonToken.StartArray);
if (((RavenJArray)token).Length > 0) // to prevent object creation if inner array is null
{
foreach (var item in ((RavenJArray)token))
foreach (var i in ReadRavenJToken(item))
yield return i;
}
yield return new ReadState(JsonToken.EndArray);
}
else if (token is RavenJObject)
{
yield return new ReadState(JsonToken.StartObject);
foreach (var prop in ((RavenJObject)token))
{
yield return new ReadState(JsonToken.PropertyName, prop.Key);
foreach (var item in ReadRavenJToken(prop.Value))
yield return item;
}
yield return new ReadState(JsonToken.EndObject);
}
}
示例10: ExecuteInternal
private void ExecuteInternal(RavenJToken token, string prefix)
{
if (token == null)
return; // nothing to do
switch (token.Type)
{
case JTokenType.Array:
foreach (var item in (RavenJArray)token)
{
ExecuteInternal(item, prefix);
}
break;
case JTokenType.String:
LoadId(token.Value<string>(), prefix);
break;
case JTokenType.Integer:
LoadId(token.Value<int>().ToString(CultureInfo.InvariantCulture), prefix);
break;
default:
// here we ignore everything else
// if it ain't a string or array, it is invalid
// as an id
break;
}
}
示例11: RavenJTokenReader
/// <summary>
/// Initializes a new instance of the <see cref="RavenJTokenReader"/> class.
/// </summary>
/// <param name="token">The token to read from.</param>
public RavenJTokenReader(RavenJToken token)
{
if (token == null)
throw new ArgumentNullException("token");
_root = token;
}
示例12: ExecuteInternal
private static void ExecuteInternal(RavenJToken token, string prefix, Func<string, string, bool> loadId)
{
if (token == null)
return; // nothing to do
switch (token.Type)
{
case JTokenType.Array:
foreach (var item in (RavenJArray)token)
{
ExecuteInternal(item, prefix, loadId);
}
break;
case JTokenType.String:
var value = token.Value<string>();
if (loadId(value, null) == false)
loadId(value, prefix);
break;
case JTokenType.Integer:
try
{
loadId(token.Value<long>().ToString(CultureInfo.InvariantCulture), prefix);
}
catch (OverflowException)
{
loadId(token.Value<ulong>().ToString(CultureInfo.InvariantCulture), prefix);
}
break;
// here we ignore everything else
// if it ain't a string or array, it is invalid
// as an id
}
}
示例13: HandleToken
private IEnumerable<IEnumerable<AbstractField>> HandleToken(RavenJToken value, string path)
{
switch (value.Type)
{
case JTokenType.Array:
foreach (var item in ((RavenJArray) value).SelectMany(val => HandleToken(val, path)))
{
yield return item;
}
break;
case JTokenType.Object:
foreach (var inner in ((RavenJObject)value))
{
var nestedObj = inner.Value as RavenJObject;
if(nestedObj!=null)
{
foreach (var item in HandleObject(nestedObj, path + "_" + inner.Key))
{
yield return item;
}
}
else
{
foreach (var item in HandleToken(inner.Value, path +"_" + inner.Key))
{
yield return item;
}
}
}
break;
default:
yield return CreateField(path, value);
break;
}
}
示例14: GetTheNewResultOrWireTheDefault
private RavenJToken GetTheNewResultOrWireTheDefault(RavenJToken result)
{
var selectToken = result.SelectToken(Name);
if (selectToken != null)
return selectToken;
return ((RavenJObject)result)[Name] = new RavenJObject();
}
示例15: Add
// This is called only from inside persistenceStore.Write
public void Add(RavenJToken key)
{
IComparable actualKey = transform(key);
Index = Index.AddOrUpdate(actualKey,
new EmptyAVLTree<RavenJToken, RavenJToken>(RavenJTokenComparer.Instance, token => token.CloneToken(), token => token.CloneToken()).Add(key, key),
(comparable, tree) => tree.Add(key, key));
}