Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 177589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:04:52+00:00 2026-05-11T14:04:52+00:00

Fluent interfaces is a fairly hot topic these days. C# 3.0 has some nice

  • 0

‘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 that each method call returns something useful, often the same object you called the method on, so you can keep chaining things. Martin Fowler discusses it with a Java example here. The concept kooks something like this:

var myListOfPeople = new List<Person>();  var person = new Person(); person.SetFirstName('Douglas').SetLastName('Adams').SetAge(42).AddToList(myListOfPeople); 

I have seen some incredibly useful fluent interfaces in C# (one example is the fluent approach for validating parameters found in an earlier StackOverflow question I had asked. It blew me away. It was able to give highly readable syntax for expressing parameter validation rules, and also, if there were no exceptions, it was able to avoid instantiating any objects! So for the ‘normal case’, there was very little overhead. This one tidbit taught me a huge amount in a short time. I want to find more things like that).

So, I’d like to learn more by looking at and discussing some excellent examples. So, what are some excellent fluent interfaces you’ve made or seen in C#, and what made them so valuable?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:04:53+00:00Added an answer on May 11, 2026 at 2:04 pm

    Kudos for the method parameter validation, you’ve given me a new idea for our fluent APIs. I’ve hated our precondition checks anyways…

    I’ve built a extensibility system for a new product in development, where you can fluently describe the commands available, the user interface elements and more. This runs on top of StructureMap and FluentNHibernate, which are nice APIs too.

    MenuBarController mb; // ... mb.Add(Resources.FileMenu, x => {   x.Executes(CommandNames.File);   x.Menu     .AddButton(Resources.FileNewCommandImage, Resources.FileNew, Resources.FileNewTip, y => y.Executes(CommandNames.FileNew))     .AddButton(null, Resources.FileOpen, Resources.FileOpenTip, y =>      {       y.Executes(CommandNames.FileOpen);       y.Menu         .AddButton(Resources.FileOpenFileCommandImage, Resources.OpenFromFile, Resources.OpenFromFileTop, z => z.Executes(CommandNames.FileOpenFile))         .AddButton(Resources.FileOpenRecordCommandImage, Resources.OpenRecord, Resources.OpenRecordTip, z => z.Executes(CommandNames.FileOpenRecord));      })      .AddSeperator()      .AddButton(null, Resources.FileClose, Resources.FileCloseTip, y => y.Executes(CommandNames.FileClose))      .AddSeperator();      // ... }); 

    And you can configure all commands available like this:

    Command(CommandNames.File)   .Is<DummyCommand>()   .AlwaysEnabled();  Command(CommandNames.FileNew)   .Bind(Shortcut.CtrlN)   .Is<FileNewCommand>()   .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered);  Command(CommandNames.FileSave)   .Bind(Shortcut.CtrlS)   .Enable(WorkspaceStatusProviderNames.DocumentOpen)   .Is<FileSaveCommand>();  Command(CommandNames.FileSaveAs)   .Bind(Shortcut.CtrlShiftS)   .Enable(WorkspaceStatusProviderNames.DocumentOpen)   .Is<FileSaveAsCommand>();  Command(CommandNames.FileOpen)   .Is<FileOpenCommand>()   .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered);  Command(CommandNames.FileOpenFile)   .Bind(Shortcut.CtrlO)   .Is<FileOpenFileCommand>()   .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered);  Command(CommandNames.FileOpenRecord)   .Bind(Shortcut.CtrlShiftO)   .Is<FileOpenRecordCommand>()   .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered); 

    Our view configure their controls for the standard edit menu commands using a service given to them by the workspace, where they just tell it to observe them:

    Workspace   .Observe(control1)   .Observe(control2) 

    If the user tabs to the controls, the workspace automatically gets an appropriate adapter for the control and provides undo/redo and clipboard operations.

    It has helped us reduce the setup code dramatically and make it even more readable.


    I forgot to tell about a library we’re using in our WinForms MVP model presenters to validate the views: FluentValidation. Really easy, really testable, really nice!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not entirely familiar with Doctrine_RawSql, but a placeholder should… May 12, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer did you try adding the following to your css div#MySilverLightDiv… May 12, 2026 at 1:09 am
  • Editorial Team
    Editorial Team added an answer Typically, I would create a public constructor with parameters that… May 12, 2026 at 1:09 am

Related Questions

i'm fairly new to NHibernate and although I'm finding tons of infos on NHibernate
I am looking at using an ORM in PHP for the first time. Until
I'm after some good tips for fluent interfaces in C#. I'm just learning about
Starting with this code: new Person(ET).WithAge(88) How can it be refactored to: new Person(ET,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.