Skip to content

Instantly share code, notes, and snippets.

@mkojoa
Created January 28, 2021 12:04
Show Gist options
  • Save mkojoa/37cfc3874032bd9a49cfa768b7c998a9 to your computer and use it in GitHub Desktop.
Save mkojoa/37cfc3874032bd9a49cfa768b7c998a9 to your computer and use it in GitHub Desktop.
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