Vogen icon indicating copy to clipboard operation
Vogen copied to clipboard

Feature: Support format parameters with string interpolation

Open Khaos66 opened this issue 1 year ago • 2 comments

Describe the feature

Just a small quality of life improvement.

Steps to reproduce

Having this ValueObject

[ValueObject<DateTime>]
public partial struct MyDate;

When used with string interpolation the ToString Method of MyDate doesn't accept the string format parameter and so the format isn't applied

var date = MyDate.From(DateTime.Now);
string text = $"This doesn't work: {date:o}";

Workaround

Casting the ValueObject to it's primitive type can be used as workaround. But is very error prone, as there is no error thrown in the frist example:

var date = MyDate.From(DateTime.Now);
string text = $"This does work: {(DateTime)date:o}";

Work needed

So I guess this feature request is about forwarding the parameters of ToString to the primitive type correctly. DateTime has 4 sets of parameters for ToString The source gen would need to lookup the ToString variants and generate wrappers.

Khaos66 avatar May 14 '24 10:05 Khaos66

Hi, thanks for the feedback. It should hoist ToString overloads from the primitive that it wraps. I'll check the config required and let you know

SteveDunn avatar May 14 '24 17:05 SteveDunn

Actually, it's string comparison that is hoisted.

I think this would make an excellent addition, thanks again for the feedback!

SteveDunn avatar May 14 '24 17:05 SteveDunn

@Khaos66 - this has now been released in 5.0.5-beta.2 Thanks for the feedback!

SteveDunn avatar Oct 28 '24 05:10 SteveDunn