Created
January 28, 2021 12:04
-
-
Save mkojoa/37cfc3874032bd9a49cfa768b7c998a9 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
namespace App | |
{ | |
class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
MailTemplate | |
.Configure | |
.With(mt => mt.To = "michaelameyaw7@gmail.com") | |
.With(mt => mt.From = "example@gmail.com") | |
.With(mt => mt.Subject = "Fluent syntax in CSharp") | |
.With(mt => mt.Body = "Hello, this is mail body") | |
.With(mt => mt.Attachement = "file.pdf") | |
.Build(); | |
Console.ReadKey(); | |
} | |
} | |
public class MailTemplate | |
{ | |
// regular auto properties | |
public string To { get; set; } | |
public string From { get; set; } | |
public string Subject { get; set; } | |
public string Body { get; set; } | |
public string Attachement { get; set; } | |
public static MailTemplate Configure { get => new MailTemplate(); } | |
public MailTemplate With(Action<MailTemplate> func) | |
{ | |
func(this); | |
return this; | |
} | |
internal void Build() | |
{ | |
Console.WriteLine("Sending the mail...."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment