SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
890 stars 46 forks source link

Feature: Support format parameters with string interpolation #593

Closed Khaos66 closed 1 month ago

Khaos66 commented 6 months ago

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.

SteveDunn commented 6 months ago

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 commented 6 months ago

Actually, it's string comparison that is hoisted.

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

SteveDunn commented 4 weeks ago

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