Closed axunonb closed 2 years ago
Throughout all IFormatter
s, Placeholder
s are only used to output values. Changing this principle would have quite an impact. E.g.: Placeholder
s use a value, that can also be formatted. So should the original or the formatted value be used? How to deal with complex types?
var data = new {
x = 3,
y = 3,
};
// This DOES WORK - placeholders are not evaluated yet when comparing
Console.WriteLine(Smart.Format("The point ({x}, {y}) {x:choose({y}):is|is not} on the line y = x", data));
Console.WriteLine(Smart.Format("The point ({x}, {y}) {x:cond:={y}?is|is not} on the line y = x", data));
// This is a workaround with minimal effort and an easily understandable format string:
Console.WriteLine(Smart.Format("The point ({x}, {y}) {1:choose(True):is|is not} on the line y = x", data, data.x == data.y));
Console.WriteLine(Smart.Format("The point ({x}, {y}) {1:cond:is|is not} on the line y = x", data, data.x == data.y));
Discussed in https://github.com/axuno/SmartFormat/discussions/249