Skip to content

Instantly share code, notes, and snippets.

@pjsvis
Created December 11, 2014 13:23
Show Gist options
  • Save pjsvis/780d930b87ce8ea5cc48 to your computer and use it in GitHub Desktop.
Save pjsvis/780d930b87ce8ea5cc48 to your computer and use it in GitHub Desktop.
Using LINQ to simplify business rules
// Ref: http://odetocode.com/Articles/739.aspx
// Using LINQ to simplify business rules
Employee employee =
new Employee { ID = 1, Name =
"Poonam", DepartmentID = 1 };
Func<Employee, bool>[] validEmployeeRules =
{
e => e.DepartmentID > 0,
e => !String.IsNullOrEmpty(e.Name),
e => e.ID > 0
};
bool isValidEmployee =
validEmployeeRules.All(rule => rule(employee));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment