本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.OfType方法的具体用法?C# JArray.OfType怎么用?C# JArray.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JArray
的用法示例。
在下文中一共展示了JArray.OfType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateValues
/// <summary>
/// The validate values.
/// </summary>
/// <param name="controls">
/// The controls.
/// </param>
/// <param name="data">
/// The data.
/// </param>
/// <param name="errorList">
/// The errorList.
/// </param>
private static void ValidateValues(JArray controls, JObject data, List<ValidationError> errorList)
{
foreach (JObject child in controls.OfType<JObject>())
{
IDynamicControl control = BaseControl.CreateControl(child);
IDynamicValueControl valueControl = control as IDynamicValueControl;
JProperty dataValue = null;
if (valueControl != null)
{
dataValue = data.Children<JProperty>().FirstOrDefault(p => p.Name == child.Value<string>("name"));
if (dataValue != null)
{
JObject dataObject = dataValue.First as JObject;
if (dataObject != null)
{
JObject roles = child["checkedRoles"] as JObject;
if (roles != null)
{
if (roles.Value<bool>("required") && string.IsNullOrEmpty(dataObject.Value<string>("value")))
{
errorList.Add(new RequiredDataError(child.Value<string>("name")));
}
}
dataObject.Add(new JProperty("checked", true));
}
}
else
{
errorList.Add(new MissingDataError(child.Value<string>("name")));
}
}
IDynamicParentControl parentControl = control as IDynamicParentControl;
if (parentControl != null)
{
JArray children = child.Value<JArray>("childs");
if (children != null)
{
JObject anyChildren = children.OfType<JObject>().FirstOrDefault(c => c.Value<string>("key") == "any");
if (anyChildren != null)
{
ValidateValues(anyChildren.Value<JArray>("controls"), data, errorList);
}
if (valueControl != null && dataValue != null)
{
JObject valueChildren = children.OfType<JObject>().FirstOrDefault(c => c.Value<string>("key") == dataValue.First.Value<string>("value"));
if (valueChildren != null)
{
ValidateValues(valueChildren.Value<JArray>("controls"), data, errorList);
}
}
}
}
}
}
示例2: ConvertToValues
private static Lut ConvertToValues(JArray obj) {
var values = new Lut();
if (obj == null) return values;
foreach (var entry in obj.OfType<JArray>()) {
double x, y;
if (FlexibleParser.TryParseDouble(Convert.ToString(entry[0], CultureInfo.InvariantCulture), out x) &&
FlexibleParser.TryParseDouble(Convert.ToString(entry[1], CultureInfo.InvariantCulture), out y)) {
values.Add(new LutPoint(x, y));
}
}
return values;
}
示例3: SetCalculatedData
public void SetCalculatedData(JArray calculatedData)
{
//.Where(p=>!((new int[]{5,3}).Contains((int)p["ParameterType"])))
OutputParameters = calculatedData.OfType<JObject>().Where(ShowOutputParameter).Select(p => new EffectsOutputParameterViewModel() {Data = p});
Contours = new GraphicCollection(calculatedData.OfType<JObject>().Where(IsContourParameter).Select(p=>((string)p["Data"]["Value"]).ToGraphic(new SpatialReference(28992), new SpatialReference(28992))));
}
示例4: SetModelData
public void SetModelData(JArray modelData)
{
Models.Clear();
foreach (
var model in modelData.OfType<JObject>().Select(model => new ModelSelectionViewModel() {Data = model}))
{
Models.Add(model);
}
}
示例5: GetColumnsFromItems
internal IDictionary<string, Column> GetColumnsFromItems(JArray items)
{
Contract.Requires(items != null, "item cannot be null");
IDictionary<string, Column> cols = new Dictionary<string, Column>();
IEnumerator<IDictionary<string, JToken>> objects = items.OfType<IDictionary<string, JToken>>().GetEnumerator();
objects.MoveNext();
ICollection<string> columnsToDetermine = objects.Current.Keys;
do
{
IList<string> nullColumns = new List<string>();
foreach (var key in columnsToDetermine)
{
JToken token;
if(defaultColumns.ContainsKey(key))
{
cols.Add(key, defaultColumns[key]);
}
else if (objects.Current.TryGetValue(key, out token))
{
JValue val = token as JValue;
if (val != null)
{
if (val.Value == null)
{
nullColumns.Add(key);
}
else
{
cols.Add(key, new Column(key, ColumnTypeHelper.GetColumnTypeForClrType(val.Value.GetType()), true));
}
}
}
}
columnsToDetermine = nullColumns;
}
while (columnsToDetermine.Count > 0 && objects.MoveNext());
return cols;
}
示例6: RemoveArrayElements
private static void RemoveArrayElements(JArray array, string currentPath, Func<string, bool> shouldSerialize, Dictionary<string, bool> cache)
{
array.OfType<JObject>()
.ToList()
.ForEach(childObject => RemoveObjectProperties(childObject, currentPath, shouldSerialize, cache));
RemoveArrayIfEmpty(array);
}