本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.ContainsKey方法的具体用法?C# JObject.ContainsKey怎么用?C# JObject.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connect
public void connect(string url, string[] protocols, JObject options, int id)
{
var webSocket = new MessageWebSocket();
webSocket.Control.MessageType = SocketMessageType.Utf8;
if (protocols != null)
{
foreach (var protocol in protocols)
{
webSocket.Control.SupportedProtocols.Add(protocol);
}
}
if (options != null && options.ContainsKey("origin"))
{
throw new NotImplementedException(/* TODO: (#253) */);
}
webSocket.MessageReceived += (sender, args) =>
{
OnMessageReceived(id, sender, args);
};
webSocket.Closed += (sender, args) =>
{
OnClosed(id, sender, args);
};
InitializeInBackground(id, url, webSocket);
}
示例2: showAlert
public void showAlert(
JObject config,
ICallback errorCallback,
ICallback actionCallback)
{
var message = config.Value<string>("message") ?? "";
var title = config.Value<string>("title") ?? "";
bool containsTitle = config.ContainsKey("title");
bool containsPositive = config.ContainsKey(DialogModuleHelper.KeyButtonPositive);
bool containsNegative = config.ContainsKey(DialogModuleHelper.KeyButtonNegative);
if (containsPositive && containsNegative)
{
var result = MessageBox.Show(message, title, MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
actionCallback.Invoke(DialogModuleHelper.ActionButtonClicked, DialogModuleHelper.KeyButtonPositiveValue);
}
else
{
actionCallback.Invoke(DialogModuleHelper.ActionButtonClicked, DialogModuleHelper.KeyButtonNegativeValue);
}
}
else if (containsPositive)
{
var result = MessageBox.Show(message, title, MessageBoxButton.OK);
if (result == MessageBoxResult.OK)
{
actionCallback.Invoke(DialogModuleHelper.ActionButtonClicked, DialogModuleHelper.KeyButtonPositiveValue);
}
}
else if (containsTitle)
{
MessageBox.Show(message, title);
}
else
{
MessageBox.Show(message);
}
}
示例3: showAlert
public void showAlert(
JObject config,
ICallback errorCallback,
ICallback actionCallback)
{
var message = config.Value<string>("message") ?? "";
var messageDialog = new MessageDialog(message)
{
Title = config.Value<string>("title"),
};
if (config.ContainsKey(DialogModuleHelper.KeyButtonPositive))
{
messageDialog.Commands.Add(new UICommand
{
Label = config.Value<string>(DialogModuleHelper.KeyButtonPositive),
Id = DialogModuleHelper.KeyButtonPositiveValue,
Invoked = target => OnInvoked(target, actionCallback),
});
}
if (config.ContainsKey(DialogModuleHelper.KeyButtonNegative))
{
messageDialog.Commands.Add(new UICommand
{
Label = config.Value<string>(DialogModuleHelper.KeyButtonNegative),
Id = DialogModuleHelper.KeyButtonNegativeValue,
Invoked = target => OnInvoked(target, actionCallback),
});
}
RunOnDispatcher(async () =>
{
if (_isInForeground)
{
await messageDialog.ShowAsync().AsTask().ConfigureAwait(false);
}
else
{
_pendingDialog = messageDialog;
}
});
}
示例4: FromRDF
/// <summary>Converts RDF statements into JSON-LD.</summary>
/// <remarks>Converts RDF statements into JSON-LD.</remarks>
/// <param name="statements">the RDF statements.</param>
/// <param name="options">the RDF conversion options.</param>
/// <param name="callback">(err, output) called once the operation completes.</param>
/// <exception cref="JSONLDProcessingError">JSONLDProcessingError</exception>
/// <exception cref="JsonLD.Core.JsonLdError"></exception>
public virtual JArray FromRDF(RDFDataset dataset)
{
// 1)
JObject defaultGraph = new JObject();
// 2)
JObject graphMap = new JObject();
graphMap["@default"] = defaultGraph;
// 3/3.1)
foreach (string name in dataset.GraphNames())
{
IList<RDFDataset.Quad> graph = dataset.GetQuads(name);
// 3.2+3.4)
JObject nodeMap;
if (!graphMap.ContainsKey(name))
{
nodeMap = new JObject();
graphMap[name] = nodeMap;
}
else
{
nodeMap = (JObject)graphMap[name];
}
// 3.3)
if (!"@default".Equals(name) && !Obj.Contains(defaultGraph, name))
{
defaultGraph[name] = new JsonLdApi.NodeMapNode(this, name);
}
// 3.5)
foreach (RDFDataset.Quad triple in graph)
{
string subject = triple.GetSubject().GetValue();
string predicate = triple.GetPredicate().GetValue();
RDFDataset.Node @object = triple.GetObject();
// 3.5.1+3.5.2)
JsonLdApi.NodeMapNode node;
if (!nodeMap.ContainsKey(subject))
{
node = new JsonLdApi.NodeMapNode(this, subject);
nodeMap[subject] = node;
}
else
{
node = (NodeMapNode)nodeMap[subject];
}
// 3.5.3)
if ((@object.IsIRI() || @object.IsBlankNode()) && !nodeMap.ContainsKey(@object.GetValue
()))
{
nodeMap[@object.GetValue()] = new JsonLdApi.NodeMapNode(this, @object.GetValue());
}
// 3.5.4)
if (JSONLDConsts.RdfType.Equals(predicate) && (@object.IsIRI() || @object.IsBlankNode
()) && !opts.GetUseRdfType())
{
JsonLdUtils.MergeValue(node, "@type", @object.GetValue());
continue;
}
// 3.5.5)
JObject value = @object.ToObject(opts.GetUseNativeTypes());
// 3.5.6+7)
JsonLdUtils.MergeValue(node, predicate, value);
// 3.5.8)
if (@object.IsBlankNode() || @object.IsIRI())
{
// 3.5.8.1-3)
((NodeMapNode)nodeMap[@object.GetValue()]).usages.Add(new JsonLdApi.UsagesNode(this, node, predicate
, value));
}
}
}
// 4)
foreach (string name_1 in graphMap.GetKeys())
{
JObject graph = (JObject)graphMap[name_1];
// 4.1)
if (!graph.ContainsKey(JSONLDConsts.RdfNil))
{
continue;
}
// 4.2)
JsonLdApi.NodeMapNode nil = (NodeMapNode)graph[JSONLDConsts.RdfNil];
// 4.3)
foreach (JsonLdApi.UsagesNode usage in nil.usages)
{
// 4.3.1)
JsonLdApi.NodeMapNode node = usage.node;
string property = usage.property;
JObject head = usage.value;
// 4.3.2)
JArray list = new JArray();
JArray listNodes = new JArray();
// 4.3.3)
while (JSONLDConsts.RdfRest.Equals(property) && node.IsWellFormedListNode())
//.........这里部分代码省略.........
示例5: FilterNode
/// <exception cref="JsonLD.Core.JsonLdError"></exception>
private bool FilterNode(JsonLdApi.FramingContext state, JObject node, JObject frame)
{
JToken types = frame["@type"];
if (!types.IsNull())
{
if (!(types is JArray))
{
throw new JsonLdError(JsonLdError.Error.SyntaxError, "frame @type must be an array"
);
}
JToken nodeTypes = node["@type"];
if (nodeTypes.IsNull())
{
nodeTypes = new JArray();
}
else
{
if (!(nodeTypes is JArray))
{
throw new JsonLdError(JsonLdError.Error.SyntaxError, "node @type must be an array"
);
}
}
if (((JArray)types).Count == 1 && ((JArray)types)[0] is JObject
&& ((JObject)((JArray)types)[0]).Count == 0)
{
return !((JArray)nodeTypes).IsEmpty();
}
else
{
foreach (JToken i in (JArray)nodeTypes)
{
foreach (JToken j in (JArray)types)
{
if (JsonLdUtils.DeepCompare(i, j))
{
return true;
}
}
}
return false;
}
}
else
{
foreach (string key in frame.GetKeys())
{
if ("@id".Equals(key) || !JsonLdUtils.IsKeyword(key) && !(node.ContainsKey(key)))
{
return false;
}
}
return true;
}
}
示例6: Frame
/// <summary>Frames subjects according to the given frame.</summary>
/// <remarks>Frames subjects according to the given frame.</remarks>
/// <param name="state">the current framing state.</param>
/// <param name="subjects">the subjects to filter.</param>
/// <param name="frame">the frame.</param>
/// <param name="parent">the parent subject or top-level array.</param>
/// <param name="property">the parent property, initialized to null.</param>
/// <exception cref="JSONLDProcessingError">JSONLDProcessingError</exception>
/// <exception cref="JsonLD.Core.JsonLdError"></exception>
private void Frame(JsonLdApi.FramingContext state, JObject nodes
, JObject frame, JToken parent, string property)
{
// filter out subjects that match the frame
JObject matches = FilterNodes(state, nodes, frame);
// get flags for current frame
bool embedOn = GetFrameFlag(frame, "@embed", state.embed);
bool explicitOn = GetFrameFlag(frame, "@explicit", [email protected]);
// add matches to output
JArray ids = new JArray(matches.GetKeys());
ids.SortInPlace();
foreach (string id in ids)
{
if (property == null)
{
state.embeds = new Dictionary<string, JsonLdApi.EmbedNode>();
}
// start output
JObject output = new JObject();
output["@id"] = id;
// prepare embed meta info
JsonLdApi.EmbedNode embeddedNode = new JsonLdApi.EmbedNode(this);
embeddedNode.parent = parent;
embeddedNode.property = property;
// if embed is on and there is an existing embed
if (embedOn && state.embeds.ContainsKey(id))
{
JsonLdApi.EmbedNode existing = state.embeds[id];
embedOn = false;
if (existing.parent is JArray)
{
foreach (JToken p in (JArray)(existing.parent))
{
if (JsonLdUtils.CompareValues(output, p))
{
embedOn = true;
break;
}
}
}
else
{
// existing embed's parent is an object
if (((JObject)existing.parent).ContainsKey(existing.property))
{
foreach (JToken v in (JArray)((JObject)existing.parent)[existing.property])
{
if (v is JObject && ((JObject)v)["@id"].SafeCompare(id))
{
embedOn = true;
break;
}
}
}
}
// existing embed has already been added, so allow an overwrite
if (embedOn)
{
RemoveEmbed(state, id);
}
}
// not embedding, add output without any other properties
if (!embedOn)
{
AddFrameOutput(state, parent, property, output);
}
else
{
// add embed meta info
state.embeds[id] = embeddedNode;
// iterate over subject properties
JObject element = (JObject)matches[id];
JArray props = new JArray(element.GetKeys());
props.SortInPlace();
foreach (string prop in props)
{
// copy keywords to output
if (JsonLdUtils.IsKeyword(prop))
{
output[prop] = JsonLdUtils.Clone(element[prop]);
continue;
}
// if property isn't in the frame
if (!frame.ContainsKey(prop))
{
// if explicit is off, embed values
if (!explicitOn)
{
EmbedValues(state, element, prop, output);
}
continue;
//.........这里部分代码省略.........
示例7: HandleTradeResult
private void HandleTradeResult(TradeResult result, JObject order)
{
if (result.IsSuccessful)
{
if (result.Position != null)
{
var p = result.Position;
JObject o = new JObject(
new JProperty("cmd", "position_created_result"),
new JProperty("_callbackId", order.ContainsKey("_callbackId") ? (string)order["_callbackId"] : null),
new JProperty("payload", new JObject(
new JProperty("label", p.Label),
new JProperty("_id", p.Id),
new JProperty("id", p.Label.Split('|')[0]),
new JProperty("symbol", p.SymbolCode.ToLower()),
new JProperty("openprice", p.EntryPrice),
new JProperty("etime", p.EntryTime.ToUnixTime()),
new JProperty("sl", p.StopLoss),
new JProperty("tp", p.TakeProfit)
)));
_publishMessage(o);
}
else if (result.PendingOrder != null)
{
JObject o = new JObject(
new JProperty("cmd", "order_created_result"),
new JProperty("_callbackId", order.ContainsKey("_callbackId") ? (string)order["_callbackId"] : null),
new JProperty("payload", new JObject(
new JProperty("label", result.PendingOrder.Label),
new JProperty("_id", result.PendingOrder.Id),
new JProperty("id", result.PendingOrder.Label.Split('|')[0])
)
));
_publishMessage(o);
}
}
else
{
JObject o = new JObject(
new JProperty("cmd", "order_create_failed_result"),
new JProperty("_callbackId", order.ContainsKey("_callbackId") ? (string)order["_callbackId"] : null),
new JProperty("payload", new JObject(
new JProperty("label", (string)order["label"])
)
));
_publishMessage(o);
}
}
示例8: Resolve
/// <exception cref="JsonLD.Core.JsonLdError"></exception>
private static void Resolve(JToken input, JObject cycles)
{
Pattern regex = Pattern.Compile("(http|https)://(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@!\\-/]))?"
);
if (cycles.Count > MaxContextUrls)
{
throw new JsonLdError(JsonLdError.Error.UnknownError);
}
// for tracking the URLs to resolve
JObject urls = new JObject();
// find all URLs in the given input
if (!FindContextUrls(input, urls, false))
{
// finished
FindContextUrls(input, urls, true);
}
// queue all unresolved URLs
JArray queue = new JArray();
foreach (string url in urls.GetKeys())
{
if (urls[url].SafeCompare(false))
{
// validate URL
if (!regex.Matcher(url).Matches())
{
throw new JsonLdError(JsonLdError.Error.UnknownError);
}
queue.Add(url);
}
}
// resolve URLs in queue
int count = queue.Count;
foreach (string url_1 in queue)
{
// check for context URL cycle
if (cycles.ContainsKey(url_1))
{
throw new JsonLdError(JsonLdError.Error.UnknownError);
}
JObject _cycles = (JObject)Clone(cycles);
_cycles[url_1] = true;
try
{
JObject ctx = (JObject)new DocumentLoader().LoadDocument(url_1).Document;
if (!ctx.ContainsKey("@context"))
{
ctx = new JObject();
ctx["@context"] = new JObject();
}
Resolve(ctx, _cycles);
urls[url_1] = ctx["@context"];
count -= 1;
if (count == 0)
{
FindContextUrls(input, urls, true);
}
}
//catch (JsonParseException)
//{
// throw new JsonLdError(JsonLdError.Error.UnknownError);
//}
//catch (MalformedURLException)
//{
// throw new JsonLdError(JsonLdError.Error.UnknownError);
//}
catch (IOException)
{
throw new JsonLdError(JsonLdError.Error.UnknownError);
}
}
}
示例9: AddValue
// //////////////////////////////////////////////////// OLD CODE BELOW
/// <summary>Adds a value to a subject.</summary>
/// <remarks>
/// Adds a value to a subject. If the value is an array, all values in the
/// array will be added.
/// Note: If the value is a subject that already exists as a property of the
/// given subject, this method makes no attempt to deeply merge properties.
/// Instead, the value will not be added.
/// </remarks>
/// <param name="subject">the subject to add the value to.</param>
/// <param name="property">the property that relates the value to the subject.</param>
/// <param name="value">the value to add.</param>
/// <?></?>
/// <?></?>
internal static void AddValue(JObject subject, string property
, JToken value, bool propertyIsArray, bool allowDuplicate)
{
if (IsArray(value))
{
if (((JArray)value).Count == 0 && propertyIsArray && !subject.ContainsKey(property
))
{
subject[property] = new JArray();
}
foreach (JToken val in (JArray)value)
{
AddValue(subject, property, val, propertyIsArray, allowDuplicate);
}
}
else
{
if (subject.ContainsKey(property))
{
// check if subject already has the value if duplicates not allowed
bool hasValue = !allowDuplicate && HasValue(subject, property, value);
// make property an array if value not present or always an array
if (!IsArray(subject[property]) && (!hasValue || propertyIsArray))
{
JArray tmp = new JArray();
tmp.Add(subject[property]);
subject[property] = tmp;
}
// add new value
if (!hasValue)
{
((JArray)subject[property]).Add(value);
}
}
else
{
// add new value as a set or single value
JToken tmp;
if (propertyIsArray)
{
tmp = new JArray();
((JArray)tmp).Add(value);
}
else
{
tmp = value;
}
subject[property] = tmp;
}
}
}
示例10: HandleGetOrders
private void HandleGetOrders(JObject msg)
{
var orders = this.PendingOrders.AsQueryable();
if (msg.ContainsKey("magic"))
{
orders = orders.Where(p => p.Label.Contains((string)msg["magic"]));
}
if (msg.ContainsKey("symbol"))
{
orders = orders.Where(p => p.SymbolCode == ((string)msg["symbol"]).ToUpper());
}
var jarray = new JArray();
foreach (var p in orders)
{
jarray.Add(
new JObject(
new JProperty("_id", p.Id),
new JProperty("id", p.Label.Split('|')[0]),
new JProperty("symbol", p.SymbolCode.ToLower()),
new JProperty("price", p.TargetPrice),
new JProperty("lot", p.Quantity),
new JProperty("tp", p.TakeProfitPips),
new JProperty("sl", p.StopLossPips),
new JProperty("label", p.Label),
new JProperty("note", p.Comment),
new JProperty("type", p.TradeType.ToString().ToLower() + "_" + p.OrderType.ToString().ToLower())
));
}
JObject o = new JObject(
new JProperty("cmd", "get_orders_result"),
new JProperty("_callbackId", msg.ContainsKey("_callbackId") ? (string)msg["_callbackId"] : null),
new JProperty("payload", jarray));
_publishMessage(o);
}
示例11: HandleClosePosition
private void HandleClosePosition(JObject message)
{
var id = (string)message["id"];
foreach (var p in this.Positions)
{
if (p.Id.ToString() == id)
{
alreadyHandledActions.Add(_getPositionString(p, "close_position"), null);
TradeResult result = this.ClosePosition(p);
if (result.IsSuccessful)
{
JObject o = new JObject(
new JProperty("cmd", "position_closed_result"),
new JProperty("_callbackId", message.ContainsKey("_callbackId") ? (string)message["_callbackId"] : null),
new JProperty("payload", new JObject(
new JProperty("label", p.Label),
new JProperty("_id", p.Id),
new JProperty("id", p.Label.Split('|')[0]),
new JProperty("symbol", p.SymbolCode.ToLower()),
new JProperty("pips", p.Pips),
new JProperty("net_profit", p.NetProfit),
new JProperty("gross_profit", p.GrossProfit),
new JProperty("ctime", DateTime.UtcNow.ToUnixTime())
)
));
_publishMessage(o);
}
else
{
JObject o = new JObject(
new JProperty("cmd", "position_closed_failed_result"),
new JProperty("_callbackId", message.ContainsKey("_callbackId") ? (string)message["_callbackId"] : null),
new JProperty("payload", new JObject(
new JProperty("label", p.Label),
new JProperty("_id", p.Id),
new JProperty("id", p.Label.Split('|')[0]),
new JProperty("symbol", p.SymbolCode.ToLower())
)));
_publishMessage(o);
}
}
}
}
示例12: HandleCloseOrder
private void HandleCloseOrder(JObject msg)
{
var id = (string)msg["id"];
foreach (var p in this.PendingOrders)
{
if (p.Id.ToString() == id)
{
var result = this.CancelPendingOrder(p);
JObject o = new JObject(
new JProperty("cmd", "order_closed_result"),
new JProperty("_callbackId", msg.ContainsKey("_callbackId") ? (string)msg["_callbackId"] : null),
new JProperty("payload", new JObject(
new JProperty("cancelled", result.IsSuccessful),
new JProperty("label", p.Label),
new JProperty("_id", p.Id),
new JProperty("id", p.Label.Split('|')[0]),
new JProperty("symbol", p.SymbolCode.ToLower()))
));
_publishMessage(o);
}
}
}
示例13: HandleCloseAllOrders
private void HandleCloseAllOrders(JObject msg)
{
var jarray = new JArray();
var magic = (string)msg["magic"];
foreach (var p in this.PendingOrders)
{
// Only cancel these orders
if (p.Label.Contains(magic))
{
var result = this.CancelPendingOrder(p);
jarray.Add(
new JObject(
new JProperty("cancelled", result.IsSuccessful),
new JProperty("label", p.Label),
new JProperty("_id", p.Id),
new JProperty("id", p.Label.Split('|')[0]),
new JProperty("symbol", p.SymbolCode.ToLower())
));
}
}
JObject o = new JObject(
new JProperty("cmd", "cancel_orders_all_result"),
new JProperty("_callbackId", msg.ContainsKey("_callbackId") ? (string)msg["_callbackId"] : null),
new JProperty("payload", (JArray)jarray));
_publishMessage(o);
}
示例14: CreateOrder
private TradeResult CreateOrder(JObject order)
{
var symbol = this.MarketData.GetSymbol(((string)order["symbol"]).ToUpper());
TradeResult result = null;
var expiration = Server.Time.AddMinutes(order_expiration);
if (order.ContainsKey("exp"))
{
expiration = Server.Time.AddMinutes((int)order["exp"]);
}
try
{
switch ((string)order["type"])
{
case "buy_limit":
result = PlaceLimitOrder(
TradeType.Buy,
symbol,
(long)order["vol"],
(double)order["price"],
(string)order["label"],
(double)order["sl"],
(double)order["tp"],
expiration,
order.ContainsKey("comment") ? (string)order["comment"] : ""
);
break;
case "sell_limit":
result = PlaceLimitOrder(
TradeType.Sell,
symbol,
(long)order["vol"],
(double)order["price"],
(string)order["label"],
(double)order["sl"],
(double)order["tp"],
expiration,
order.ContainsKey("comment") ? (string)order["comment"] : ""
);
break;
case "buy_stop":
result = PlaceStopOrder(
TradeType.Buy,
symbol,
(long)order["vol"],
(double)order["price"],
(string)order["label"],
(double)order["sl"],
(double)order["tp"],
expiration,
order.ContainsKey("comment") ? (string)order["comment"] : ""
);
break;
case "sell_stop":
result = PlaceStopOrder(
TradeType.Sell,
symbol,
(long)order["vol"],
(double)order["price"],
(string)order["label"],
(double)order["sl"],
(double)order["tp"],
expiration,
order.ContainsKey("comment") ? (string)order["comment"] : ""
);
break;
case "sell_market":
result = ExecuteMarketOrder(
TradeType.Sell,
symbol,
(long)order["vol"],
(string)order["label"],
(double)order["sl"],
(double)order["tp"],
order.ContainsKey("range") ? (double?)order["range"] : null,
order.ContainsKey("comment") ? (string)order["comment"] : ""
);
try
{
alreadyHandledActions.Add(
_getPositionString("market_order", symbol.Code, (string)order["label"], (long)order["vol"], TradeType.Sell.ToString()), null);
}
catch (Exception ex)
{
this.Print("labels should have unique ids to prevent this: {0}", ex.Message);
}
break;
case "buy_market":
//.........这里部分代码省略.........
示例15: Expand
/// <summary>
/// Expansion Algorithm
/// http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm
/// </summary>
/// <param name="activeCtx"></param>
/// <param name="activeProperty"></param>
/// <param name="element"></param>
/// <returns></returns>
/// <exception cref="JsonLdError">JsonLdError</exception>
/// <exception cref="JsonLD.Core.JsonLdError"></exception>
public virtual JToken Expand(Context activeCtx, string activeProperty, JToken element
)
{
// 1)
if (element.IsNull())
{
return null;
}
// 3)
if (element is JArray)
{
// 3.1)
JArray result = new JArray();
// 3.2)
foreach (JToken item in (JArray)element)
{
// 3.2.1)
JToken v = Expand(activeCtx, activeProperty, item);
// 3.2.2)
if (("@list".Equals(activeProperty) || "@list".Equals(activeCtx.GetContainer(activeProperty
))) && (v is JArray || (v is JObject && ((IDictionary<string, JToken>)v).ContainsKey
("@list"))))
{
throw new JsonLdError(JsonLdError.Error.ListOfLists, "lists of lists are not permitted."
);
}
else
{
// 3.2.3)
if (!v.IsNull())
{
if (v is JArray)
{
JsonLD.Collections.AddAll(result, (JArray)v);
}
else
{
result.Add(v);
}
}
}
}
// 3.3)
return result;
}
else
{
// 4)
if (element is JObject)
{
// access helper
IDictionary<string, JToken> elem = (JObject)element;
// 5)
if (elem.ContainsKey("@context"))
{
activeCtx = activeCtx.Parse(elem["@context"]);
}
// 6)
JObject result = new JObject();
// 7)
JArray keys = new JArray(element.GetKeys());
keys.SortInPlace();
foreach (string key in keys)
{
JToken value = elem[key];
// 7.1)
if (key.Equals("@context"))
{
continue;
}
// 7.2)
string expandedProperty = activeCtx.ExpandIri(key, false, true, null, null);
JToken expandedValue = null;
// 7.3)
if (expandedProperty == null || (!expandedProperty.Contains(":") && !JsonLdUtils.IsKeyword
(expandedProperty)))
{
continue;
}
// 7.4)
if (JsonLdUtils.IsKeyword(expandedProperty))
{
// 7.4.1)
if ("@reverse".Equals(activeProperty))
{
throw new JsonLdError(JsonLdError.Error.InvalidReversePropertyMap, "a keyword cannot be used as a @reverse propery"
);
}
// 7.4.2)
if (result.ContainsKey(expandedProperty))
//.........这里部分代码省略.........