Linq - Beyond Queries: LINQ For Better Business Logic
Linq - Beyond Queries: LINQ For Better Business Logic
Extension methods
For better APIs
Expression trees
For static reflection
Funcs and Actions
For functional, declarative programming
Demos
Functional validation
Increasingly complex validations
Building a LINQ powered rules engine
Example Scenario
Readability
Easier to maintain
Essence over ceremony
Remove language clutter
Extend types!
Even sealed types, generic types, and interfaces
A readable API
Often uses method chaining
return true;
}
Functional Validation
}
A More Complex Scenario
Shape
Shape Shape
Creating the Flowchart
Tedious!
var chart = new MovieFlowchart();
chart.Shapes.Add(
new Shape<Movie, MovieResult>()
{
Name = "CheckTitle",
Arrows =
{
new Arrow<Movie>
{
PointsTo = "CheckLength",
Rule = m => !String.IsNullOrEmpty(m.Title)
}
},
RequiredField = new PropertySpecifier<Movie>(m=>m.Title)
}
// ... and so on
);
Building the Fluent API / Internal DSL