/// <inheritdoc /> public async Task <ContextObject> GetValue(ContextObject context, ScopeData scopeData) { var c = await context.GetContextForPath(Value, scopeData); if (FormatString != null && FormatString.Any()) { var argList = new List <KeyValuePair <string, object> >(); foreach (var formatterArgument in FormatString) { var value = context.FindNextNaturalContextObject().CloneForEdit(); value = await formatterArgument.Item2.GetValue(value, scopeData); if (value == null) { argList.Add(new KeyValuePair <string, object>(formatterArgument.Item1.ArgumentName, null)); } else { await value.EnsureValue(); argList.Add(new KeyValuePair <string, object>(formatterArgument.Item1.ArgumentName, value.Value)); } } //we do NOT await the task here. We await the task only if we need the value context.Value = c.Format(TargetFormatterName, argList.ToArray()); } else { context.Value = c.Format(TargetFormatterName, new KeyValuePair <string, object> [0]); } return(context); }
public override string ToString() { if (FormatString != null && FormatString.Any()) { return($"{Type} \"{Value}\" AS ({FormatString.Select(e => e.ToString()).Aggregate((e, f) => e + "," + f)})"); } return($"{Type} {Value}"); }
public override int GetHashCode() { unchecked { int hashCode = base.GetHashCode(); hashCode = (hashCode * 397) ^ (Kind != null ? Kind.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (FormatString.Any() ? FormatString.Select(f => f.Item1.GetHashCode() ^ f.Item2.GetHashCode()).Aggregate((e, f) => e ^ f) : 0); hashCode = (hashCode * 397) ^ (TargetFormatterName != null ? TargetFormatterName.GetHashCode() : 0); return(hashCode); } }
/// <inheritdoc /> public override async Task <IEnumerable <DocumentItemExecution> > Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData) { if (context == null) { return(new DocumentItemExecution[0]); } var c = await context.GetContextForPath(Value, scopeData); if (FormatString != null && FormatString.Any()) { var argList = new List <KeyValuePair <string, object> >(); foreach (var formatterArgument in FormatString) { //if pre and suffixed by a $ its a reference to another field. //walk the path in the $ and use the value in the formatter var trimmedArg = formatterArgument.Argument?.Trim(); if (trimmedArg != null && trimmedArg.StartsWith("$") && trimmedArg.EndsWith("$")) { var formatContext = await context.GetContextForPath(trimmedArg.Trim('$'), scopeData); await formatContext.EnsureValue(); argList.Add(new KeyValuePair <string, object>(formatterArgument.Name, formatContext.Value)); } else { argList.Add(new KeyValuePair <string, object>(formatterArgument.Name, formatterArgument.Argument)); } } //we do NOT await the task here. We await the task only if we need the value context.Value = c.Format(argList.ToArray()); } else { context.Value = c.Format(new KeyValuePair <string, object> [0]); } return(Children.WithScope(context)); }
/// <inheritdoc /> protected override void SerializeXml(XmlWriter writer) { base.SerializeXml(writer); writer.WriteElementString(nameof(TargetFormatterName), TargetFormatterName); if (FormatString.Any()) { writer.WriteStartElement(nameof(FormatString)); foreach (var formatStr in FormatString) { writer.WriteStartElement("Argument"); if (!string.IsNullOrWhiteSpace(formatStr.Item1.ArgumentName)) { writer.WriteAttributeString("Name", formatStr.Item1.ArgumentName); } writer.WriteStartElement(formatStr.Item2.GetType().Name); formatStr.Item2.WriteXml(writer); writer.WriteEndElement(); //formatStr.Item2.GetType().Name writer.WriteEndElement(); //Argument } writer.WriteEndElement(); //nameof(FormatString) } }