本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.AddIfNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.AddIfNotNull方法的具体用法?C# JArray.AddIfNotNull怎么用?C# JArray.AddIfNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JArray
的用法示例。
在下文中一共展示了JArray.AddIfNotNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalToJToken
/// <summary>
/// To the JToken.
/// </summary>
/// <param name="xml">The XML.</param>
/// <returns>JToken.</returns>
internal static JToken InternalToJToken(this XElement xml)
{
JToken result = null;
JTokenType tokenType;
if (Enum.TryParse<JTokenType>(xml.GetAttributeValue(attributeType), out tokenType))
{
if (xml != null)
{
switch (tokenType)
{
case JTokenType.Array:
var array = new JArray();
foreach (var one in xml.Elements())
{
array.AddIfNotNull(InternalToJToken(one));
}
result = array;
break;
//Simple types
case JTokenType.Date:
result = JToken.FromObject(Convert.ToDateTime(xml.Value));
break;
case JTokenType.Integer:
case JTokenType.Float:
result = JToken.Parse(xml.Value);
break;
case JTokenType.Boolean:
result = JToken.FromObject(xml.Value.ToBoolean(false));
break;
//Complex types
case JTokenType.Object:
var jObject = new JObject();
foreach (var one in xml.Elements())
{
// Keep compatibility for those which not use nodeNamePrefix.
var name = one.Name.LocalName.StartsWith(nodeNamePrefix) ? one.Name.LocalName.Substring(nodeNamePrefix.Length) : one.Name.LocalName;
jObject.Add(name, InternalToJToken(one));
}
result = jObject;
break;
case JTokenType.Property:
case JTokenType.Raw:
break;
case JTokenType.TimeSpan:
result = JToken.FromObject(new TimeSpan(xml.Value.ToInt64()));
break;
case JTokenType.String:
result = JToken.FromObject(xml.Value);
break;
case JTokenType.Uri:
result = JToken.FromObject(new Uri(xml.Value));
break;
case JTokenType.Bytes:
result = JToken.FromObject(Encoding.UTF8.GetBytes(xml.Value));
break;
case JTokenType.Null:
result = NullJToken;
break;
case JTokenType.Undefined:
result = UndefinedJToken;
break;
//Following option should be ignored.
case JTokenType.Comment:
case JTokenType.Constructor:
case JTokenType.None:
default:
break;
}
}
}
return result;
}
示例2: InternalDexmlize
/// <summary>
/// Internals the dexmlize.
/// </summary>
/// <param name="xml">The XML.</param>
/// <returns></returns>
private static JToken InternalDexmlize(this XElement xml)
{
JToken result = null;
JTokenType tokenType;
if (Enum.TryParse<JTokenType>(xml.GetAttributeValue(attributeType), out tokenType))
{
if (xml != null)
{
switch (tokenType)
{
case JTokenType.Array:
var array = new JArray();
foreach (var one in xml.Elements())
{
array.AddIfNotNull(InternalDexmlize(one));
}
result = array;
break;
//Simple types
case JTokenType.Date:
result = JToken.FromObject(Convert.ToDateTime(xml.Value));
break;
case JTokenType.Integer:
case JTokenType.Float:
result = JToken.Parse(xml.Value);
break;
case JTokenType.Boolean:
result = JToken.FromObject(xml.Value.ToBoolean(false));
break;
//Complex types
case JTokenType.Object:
var jObject = new JObject();
foreach (var one in xml.Elements())
{
if (one.Name.LocalName.Equals(nodeProperty, StringComparison.OrdinalIgnoreCase))
{
var name = one.GetAttributeValue(attributeName);
if (!string.IsNullOrWhiteSpace(name))
{
jObject.Add(name, InternalDexmlize(one));
}
}
}
result = jObject;
break;
case JTokenType.Property:
case JTokenType.Raw:
break;
case JTokenType.TimeSpan:
result = JToken.FromObject(new TimeSpan(xml.Value.ToInt64()));
break;
case JTokenType.String:
result = JToken.FromObject(xml.Value);
break;
case JTokenType.Uri:
result = JToken.FromObject(new Uri(xml.Value));
break;
case JTokenType.Bytes:
result = JToken.FromObject(Encoding.UTF8.GetBytes(xml.Value));
break;
case JTokenType.Null:
result = NullJToken;
break;
case JTokenType.Undefined:
result = UndefinedJToken;
break;
//Following option should be ignored.
case JTokenType.Comment:
case JTokenType.Constructor:
case JTokenType.None:
default:
break;
}
}
}
return result;
}