How to choose other property if property doesn't exist? #438
Unanswered
KamilTheDev
asked this question in
Q&A
Replies: 1 comment 5 replies
-
Hi using System;
using SmartFormat;
using SmartFormat.Core.Settings;
public class Program
{
public static void Main()
{
var data = new
{
nickname = "J",
name = "John"
};
var data2 = new
{
name = "John"
};
var settings = new SmartSettings();
settings.Formatter.ErrorAction = SmartFormat.Core.Settings.FormatErrorAction.Ignore;
var smart = Smart.CreateDefaultSmartFormat(settings);
Console.WriteLine(smart.Format("{name} {nickname}", data2));
Console.WriteLine(smart.Format("{name} {nickname}", data));
// Output:
// John
// John J
}
} Does this help in your use case, or do you need more finegrained control? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
If I had data like:
How can I make it use
nickname
if the property exists, otherwise usename
? I tried a few attempts but they will all error withCould not evaluate the selector "nickname"
for the data2.Beta Was this translation helpful? Give feedback.
All reactions