How to choose other property if property doesn't exist? #438
Answered
by
KamilTheDev
KamilTheDev
asked this question in
Q&A
-
If I had data like: var data = new
{
nickname = "J",
name = "John"
};
var data2 = new
{
name = "John"
}; How can I make it use |
Beta Was this translation helpful? Give feedback.
Answered by
KamilTheDev
Sep 29, 2024
Replies: 1 comment 9 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.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's what I came up with: