Last updated on August 1, 2017
On April 5th, I gave a live webinar on how to create fluent interfaces, and why they can make your code “mistake-proof”. It’s hosted by PostSharp – the makers of a cool library that helps you eliminate boiler-plate code from your C# and VB.NET source code.
The webinar was recorded, and is available at: http://www.postsharp.net/blog/post/webinar-recording-fluent-interfaces.
The source code is available at: https://github.com/ScottLilly/FluentInterfaceWebinar
I wrote a WPF tool to help you build fluent interfaces. You can read more about it at: https://www.scottlilly.com/fluent-interface-creator/. The source code is available on GitHub at: https://github.com/ScottLilly/FluentInterfaceCreator
It’s very sympathetic and admirable for these free C# lessons and i hope a lot more is comming. But what i miss on your website is the opportunity to show some love and apprication for your labour. Of course we respect you for the way you do things here. But perhaps you could respect us back in giving us the opportunity to show some appreciation.
Personally for me this site helps greatly in my journy of becomming a C# programmer, God bless Scott!!!
Thank you, Jan. It makes me very happy to hear when someone appreciates the work I do here. I am planning some books and paid courses to create over the next year. Until then, the best “payment” I can receive is comments like yours. For my job, I do projects for large companies. That provides a good income, but rarely provides the kind of connection I find here – and the good feeling that comes with helping someone.
Instead of casting, I think you should do this:
foreach(var salesperson in salespeople)
{
reportStarter = reportStarter.IncludeSalespersonID(salesperson);
}
Thank you. That is correct.
So, this code would work:
using System;
using System.Collections.Generic;
namespace Engine.Report.WithFI salespeople = new List {1, 3, 7};
{
public class CallingClass
{
public void MyFunction()
{
List
ICanAddSalespersonIDOrSetCategories reportStarter =
ReportGenerator
.CreateSalesReport()
.From(DateTime.UtcNow.AddMonths(-1))
.To(DateTime.UtcNow)
.IncludeSalespersonID(23);
foreach(int salesperson in salespeople)
{
reportStarter = reportStarter.IncludeSalespersonID(salesperson);
}
reportStarter
.IncludeAllCategories()
.GroupBy(ReportGenerator.GroupingMethod.Department)
.SortBy(ReportGenerator.SortMethod.DateAscending)
.IncludeReturnedOrders()
.IncludeUnshippedOrders()
.BuildReport();
}
}
}