What fluent interfaces have you made or seen in C# that were very valuable? What was so great about them?

后端 未结 11 1194
-上瘾入骨i
-上瘾入骨i 2021-01-31 05:42

\"Fluent interfaces\" is a fairly hot topic these days. C# 3.0 has some nice features (particularly extension methods) that help you make them.

FYI, a fluent API means

11条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 05:56

    I wrote a little fluent wrapper for System.Net.Mail which I find makes it email code much more readable (and easier to remember the syntax).

    var email = Email
                .From("john@email.com")
                .To("bob@email.com", "bob")
                .Subject("hows it going bob")
                .Body("yo dawg, sup?");
    
    //send normally
    email.Send();
    
    //send asynchronously
    email.SendAsync(MailDeliveredCallback);
    

    http://lukencode.com/2010/04/11/fluent-email-in-net/

提交回复
热议问题