Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FormatStringConverter.cs
1using System.Globalization;
4
6{
10 public class FormatStringConverter : IMultiValueConverter
11 {
12 // values[0] is the format string
13 // values[1..] are the format arguments
14 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
15 {
16 if (values is null || values.Length == 0)
17 return string.Empty;
18
19 string Format = values[0]?.ToString() ?? string.Empty;
20 object[] Args = values.Skip(1).ToArray();
21
22 try
23 {
24 return string.Format(culture, Format, Args);
25 }
26 catch(Exception Ex)
27 {
28 // Fallback: if something went wrong, just return format + args joined
29 ServiceRef.LogService.LogWarning($"FormatStringConverter failed: {Ex.Message}");
30 return Format + " " + string.Join(", ", Args);
31 }
32 }
33
34 public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
35 => throw new NotSupportedException();
36 }
37}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static ILogService LogService
Log service.
Definition: ServiceRef.cs:214
A converter that formats a string using a format string and arguments.
void LogWarning(string Message, params KeyValuePair< string, object?>[] Tags)
Invoke this method to add a warning statement to the log.