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

后端 未结 11 1193
-上瘾入骨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:48

    In addition to the ones specified here, the popuplar RhinoMocks unit test mock framework uses fluent syntax to specify expectations on mock objects:

    // Expect mock.FooBar method to be called with any paramter and have it invoke some method
    Expect.Call(() => mock.FooBar(null))
        .IgnoreArguments()
        .WhenCalled(someCallbackHere);
    
    // Tell mock.Baz property to return 5:
    SetupResult.For(mock.Baz).Return(5);
    

提交回复
热议问题