本文整理汇总了C#中JToken.GetTokenValue方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.GetTokenValue方法的具体用法?C# JToken.GetTokenValue怎么用?C# JToken.GetTokenValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.GetTokenValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatValue
/// <summary>
/// Format value only, simple replacement
/// </summary>
/// <param name="source">
/// The source.
/// </param>
/// <param name="format">
/// The a format.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
private static string FormatValue(JToken source, string format)
{
var sb = new StringBuilder();
var mc = RegValue.Matches(format);
var startIndex = 0;
foreach (Match m in mc)
{
var g = m.Groups[2]; // it's second in the match between { and }
var length = g.Index - startIndex - 1;
sb.Append(format.Substring(startIndex, length));
var result = source.GetTokenValue(g.Value).FirstOrDefault();
if (!string.IsNullOrEmpty(result))
{
sb.Append(result);
}
startIndex = g.Index + g.Length + 1;
}
if (startIndex < format.Length)
{
// include the rest (end) of the string
sb.Append(format.Substring(startIndex));
}
return sb.ToString();
}
示例2: FormatConditionalBlock
/// <summary>
/// Keep or erase block, this is used for boolean parameter
/// </summary>
/// <param name="source">
/// The source.
/// </param>
/// <param name="format">
/// The format.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
private static string FormatConditionalBlock(JToken source, string format)
{
var mc = RegConditional.Matches(format);
foreach (Match m in mc)
{
// Get param name
var paramName = m.Groups["tag"].Value;
var nega = paramName.StartsWith("NOT_");
paramName = paramName.Replace("NOT_", string.Empty);
var result = source.GetTokenValue(paramName).FirstOrDefault();
if (!nega)
{
if (!string.IsNullOrEmpty(result) && result != "False")
{
format = format.Replace(m.Groups[0].Value, m.Groups[2].Value);
}
else
{
format = format.Replace(m.Groups[0].Value, string.Empty);
}
}
else
{
if (string.IsNullOrEmpty(result) || result == "False")
{
format = format.Replace(m.Groups[0].Value, m.Groups[2].Value);
}
else
{
format = format.Replace(m.Groups[0].Value, string.Empty);
}
}
}
return format;
}
示例3: FormatDuplicate
/// <summary>
/// Replace block and duplicate it, this is used for array parameter
/// </summary>
/// <param name="source">
/// The source.
/// </param>
/// <param name="format">
/// The a format.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
private static string FormatDuplicate(JToken source, string format)
{
var mc = RegDuplicate.Matches(format);
foreach (Match m in mc)
{
// Get param name
var paramName = m.Groups["tag"].Value;
var results = source.GetTokenValue(paramName);
var toDuplicate = m.Groups[2].Value;
var duplicate = results.Aggregate(string.Empty, (current, value) => current + toDuplicate.Replace("{" + paramName + "}", value));
format = format.Replace(m.Groups[0].Value, duplicate);
}
return format;
}