-
-
Save mcihad/58c1b6782c45074733dab1b5c069141e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BirthDay | |
{ | |
private const string Template = | |
""" | |
Hey, | |
{name}'s birthday is on {dob}, which is in {month}. | |
Let's plan a party! | |
"""; | |
private readonly Dictionary<string, string> _parameters = new(); | |
private BirthDay(string name, DateOnly dob) | |
{ | |
_parameters.Add(@"{name}", name); | |
_parameters.Add(@"{dob}", $"{dob:MM/dd/yyyy}"); | |
_parameters.Add(@"{month}", $"{dob:MMMM}"); | |
} | |
public static BirthDay CreateInstance(string name, DateOnly dob) => new(name, dob); | |
public override string ToString() | |
=> _parameters.Aggregate(Template, (sender, kv) | |
=> sender.Replace(kv.Key, kv.Value)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = BirthDay.CreateInstance("Mary", new DateOnly(1956, 9, 21)).ToString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment